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 <new>
     18 #include <cstdlib>
     19 #include <cassert>
     20 
     21 // 0 args, return void
     22 
     23 int count = 0;
     24 
     25 void f_void_0()
     26 {
     27     ++count;
     28 }
     29 
     30 struct A_void_0
     31 {
     32     void operator()() {++count;}
     33 };
     34 
     35 void
     36 test_void_0()
     37 {
     38     int save_count = count;
     39     // function
     40     {
     41     std::function<void ()> r1(f_void_0);
     42     r1();
     43     assert(count == save_count+1);
     44     save_count = count;
     45     }
     46     // function pointer
     47     {
     48     void (*fp)() = f_void_0;
     49     std::function<void ()> r1(fp);
     50     r1();
     51     assert(count == save_count+1);
     52     save_count = count;
     53     }
     54     // functor
     55     {
     56     A_void_0 a0;
     57     std::function<void ()> r1(a0);
     58     r1();
     59     assert(count == save_count+1);
     60     save_count = count;
     61     }
     62 }
     63 
     64 int main()
     65 {
     66     test_void_0();
     67 }
     68