File: cxx17.cpp

package info (click to toggle)
visp 3.7.0-7
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 166,380 kB
  • sloc: cpp: 392,705; ansic: 224,448; xml: 23,444; python: 13,701; java: 4,792; sh: 206; objc: 145; makefile: 118
file content (25 lines) | stat: -rw-r--r-- 430 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#if __cplusplus >= 201703L || (defined(_MSC_VER) && _MSC_VER >= 1914)
// OK
#else
#error "C++17 is not supported"
#endif

#include <iostream>
#include <memory>

template <typename T> auto get_value(T t)
{
  if constexpr (std::is_pointer_v<T>)
    return *t;
  else
    return t;
}

int main()
{
  auto pi = std::make_unique<int>(9);
  int i = 9;

  std::cout << get_value(pi.get()) << "\n";
  std::cout << get_value(i) << "\n";
}