Home | History | Annotate | Download | only in func.wrap.func.inv
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <functional>
     11 
     12 // class function<R(ArgTypes...)>
     13 
     14 // R operator()(ArgTypes... args) const
     15 
     16 #include <functional>
     17 #include <cassert>
     18 
     19 // 0 args, return int
     20 
     21 int count = 0;
     22 
     23 int f_int_0()
     24 {
     25     return 3;
     26 }
     27 
     28 struct A_int_0
     29 {
     30     int operator()() {return 4;}
     31 };
     32 
     33 void
     34 test_int_0()
     35 {
     36     // function
     37     {
     38     std::function<int ()> r1(f_int_0);
     39     assert(r1() == 3);
     40     }
     41     // function pointer
     42     {
     43     int (*fp)() = f_int_0;
     44     std::function<int ()> r1(fp);
     45     assert(r1() == 3);
     46     }
     47     // functor
     48     {
     49     A_int_0 a0;
     50     std::function<int ()> r1(a0);
     51     assert(r1() == 4);
     52     }
     53 }
     54 
     55 int main()
     56 {
     57     test_int_0();
     58 }
     59