Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
is-union.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Piotr Bartosiewicz (p.bartosiewi@partner.samsung.com)
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18 
25 #ifndef CARGO_IS_UNION_HPP
26 #define CARGO_IS_UNION_HPP
27 
28 #include "cargo/is-visitable.hpp"
29 
30 namespace cargo {
31 
32 // generic member checker, start
33 template <typename T, typename F>
35  template <typename C>
36  static std::true_type check(typename F::template checker__<C>* =0);
37 
38  template <typename C>
39  static std::false_type check(...);
40 
41  static const bool value = std::is_same<decltype(check<T>(0)), std::true_type>::value;
42 };
43 
44 template <typename T, typename F>
45 struct has_member : public std::integral_constant<bool, has_member_impl<T, F>::value> {};
46 // generic member checker, end
47 
48 
49 template <typename X>
50 struct check_union : isVisitable<X> {
51  template <typename T,
52  //list of function union must implement
53  const X& (T::*)() const = &T::as,
54  X& (T::*)(const X& src) = &T::set,
55  bool (T::*)() = &T::isSet
56  >
57  struct checker__ {};
58 };
59 template<typename T>
61 
62 //Note:
63 // unfortunately, above generic has_member can't be used for isVisitable
64 // because Vistable need 'accept' OR 'accept const', while has_member make exect match
65 // e.g accept AND accept const
66 
67 } // namespace cargo
68 
69 #endif // CARGO_IS_UNION_HPP
70 
static std::true_type check(typename F::template checker__< C > *=0)
Definition: is-union.hpp:60
Internal configuration helper.
Definition: is-union.hpp:50
static const bool value
Definition: is-union.hpp:41
Helper for compile-time checking against existance of template method 'accept'.
Definition: is-visitable.hpp:49
Definition: is-union.hpp:34
Definition: is-union.hpp:45
Definition: is-union.hpp:57