]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/convert/include/boost/convert/detail/has_member.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / convert / include / boost / convert / detail / has_member.hpp
1 // Copyright (c) 2009-2016 Vladimir Batov.
2 // Use, modification and distribution are subject to the Boost Software License,
3 // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt.
4
5 #ifndef BOOST_CONVERT_HAS_MEMBER_HPP
6 #define BOOST_CONVERT_HAS_MEMBER_HPP
7
8 #include <boost/type_traits/remove_const.hpp>
9 #include <boost/type_traits/detail/yes_no_type.hpp>
10
11 // This macro allows to check if a type has a member named "__member_name__"...
12 // ... regardless of the signature. If takes advantage of the following behavior related to
13 // function resolution. Say, both, foo and base, declare a method with the same name "func":
14 //
15 // struct foo { int func (int, int) { return 0; } };
16 // struct base { void func () {} };
17 // struct mixin : public foo, public base {};
18 //
19 // Now, if we inherit from both -- foo and base -- classes, then the following calls will fail
20 // mixin_ptr(0)->func();
21 // mixin_ptr(0)->func(5, 5);
22 // with the error message (gcc): request for member func is ambiguous
23 // regardless if we provide any arguments or not even though one might expect that
24 // arg-based signature resolution might kick in. The only way to deploy those methods is:
25 //
26 // mixin_ptr(0)->foo::func();
27 // mixin_ptr(0)->base::func(5, 5);
28 //
29 // C2. The actual signature of __member_name__ is not taken into account. If
30 // __T__::__member_name__(any-signature) exists, then the introduced base::__member_name__
31 // will cause mixin->__member_name__() call to fail to compile (due to ambiguity).
32 // C3. &U::__member_name__ (a.k.a. &mixin::__member_name__)
33 // has the type of func_type only if __T__::__member_name__ does not exist.
34 // If __T__::member_name does exist, then mixin::__member_name__ is ambiguous
35 // and "yes_type test (...)" kicks in instead.
36 // C4. Need to find some unique/ugly name so that it does not clash if this macro is
37 // used inside some other template class;
38
39 #define BOOST_DECLARE_HAS_MEMBER(__trait_name__, __member_name__) \
40 \
41 template <typename __boost_has_member_T__> /*C4*/ \
42 class __trait_name__ \
43 { \
44 typedef typename ::boost::remove_const<__boost_has_member_T__>::type check_type; \
45 typedef ::boost::type_traits::yes_type yes_type; \
46 typedef ::boost::type_traits:: no_type no_type; \
47 \
48 struct base { void __member_name__(/*C2*/) {}}; \
49 struct mixin : public base, public check_type {}; \
50 \
51 template <void (base::*)()> struct aux {}; \
52 \
53 template <typename U> static no_type test(aux<&U::__member_name__>*); /*C3*/ \
54 template <typename U> static yes_type test(...); \
55 \
56 public: \
57 \
58 BOOST_STATIC_CONSTANT(bool, value = (sizeof(yes_type) == sizeof(test<mixin>(0)))); \
59 }
60
61 #endif // BOOST_CONVERT_HAS_MEMBER_HPP