]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/callable_traits/example/intro.cpp
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)
7 #include <boost/callable_traits/detail/config.hpp>
8 #ifdef BOOST_CLBL_TRTS_DISABLE_VARIABLE_TEMPLATES
9 int main(){ return 0; }
13 #include <type_traits>
15 #include <boost/callable_traits.hpp>
17 namespace ct
= boost::callable_traits
;
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
, ""); }
23 // foo is a function object
25 void operator()(int, char, float) const {}
30 // Use args_t to retrieve a parameter list as a std::tuple:
33 std::tuple
<int, char, float>
36 // has_void_return lets us perform a quick check for a void return type
37 static_assert(ct::has_void_return
<foo
>::value
, "");
39 // Detect C-style variadics (ellipses) in a signature (e.g. printf)
40 static_assert(!ct::has_varargs
<foo
>::value
, "");
42 // pmf is a pointer-to-member function: void (foo::*)(int, char, float) const
43 using pmf
= decltype(&foo::operator());
45 // remove_member_const_t lets you remove the const member qualifier
47 ct::remove_member_const_t
<pmf
>,
48 void (foo::*)(int, char, float) /*no const!*/
51 // Conversely, add_member_const_t adds a const member qualifier
54 ct::add_member_const_t
<void (foo::*)(int, char, float)>
57 // is_const_member_v checks for the presence of member const
58 static_assert(ct::is_const_member
<pmf
>::value
, "");