File: cxx-test-declval.cpp

package info (click to toggle)
libtins 4.5-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,956 kB
  • sloc: cpp: 34,550; ansic: 603; makefile: 13
file content (19 lines) | stat: -rw-r--r-- 476 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
// Example code taken from http://en.cppreference.com/w/cpp/utility/declval

#include <utility>
#include <iostream>
 
struct Default { int foo() const { return 1; } };
 
struct NonDefault
{
    NonDefault(const NonDefault&) { }
    int foo() const { return 1; }
};
 
int main()
{
    decltype(Default().foo()) n1 = 1;                   // type of n1 is int
    decltype(std::declval<NonDefault>().foo()) n2 = n1; // type of n2 is int
    return (n1 == 1 && n2 == 1) ? 0 : 1;
}