]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/callable_traits/example/intro.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / callable_traits / example / intro.cpp
1 /*<-
2 Copyright Barrett Adair 2016-2017
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt)
5 ->*/
6
7 #include <boost/callable_traits/detail/config.hpp>
8 #ifdef BOOST_CLBL_TRTS_DISABLE_VARIABLE_TEMPLATES
9 int main(){ return 0; }
10 #else
11
12 //[ intro
13 #include <type_traits>
14 #include <tuple>
15 #include <boost/callable_traits.hpp>
16
17 namespace ct = boost::callable_traits;
18
19 // This function template helps keep our example code neat
20 template<typename A, typename B>
21 void assert_same(){ static_assert(std::is_same<A, B>::value, ""); }
22
23 // foo is a function object
24 struct foo {
25 void operator()(int, char, float) const {}
26 };
27
28 int main() {
29
30 // Use args_t to retrieve a parameter list as a std::tuple:
31 assert_same<
32 ct::args_t<foo>,
33 std::tuple<int, char, float>
34 >();
35
36 // has_void_return lets us perform a quick check for a void return type
37 static_assert(ct::has_void_return<foo>::value, "");
38
39 // Detect C-style variadics (ellipses) in a signature (e.g. printf)
40 static_assert(!ct::has_varargs<foo>::value, "");
41
42 // pmf is a pointer-to-member function: void (foo::*)(int, char, float) const
43 using pmf = decltype(&foo::operator());
44
45 // remove_member_const_t lets you remove the const member qualifier
46 assert_same<
47 ct::remove_member_const_t<pmf>,
48 void (foo::*)(int, char, float) /*no const!*/
49 >();
50
51 // Conversely, add_member_const_t adds a const member qualifier
52 assert_same<
53 pmf,
54 ct::add_member_const_t<void (foo::*)(int, char, float)>
55 >();
56
57 // is_const_member_v checks for the presence of member const
58 static_assert(ct::is_const_member<pmf>::value, "");
59 }
60
61 //]
62 #endif