00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __CHOOSE_HH
00018 # define __CHOOSE_HH
00019
00020 namespace catsfoot {
00021 namespace details {
00022 template <typename...>
00023 struct generator_choose {};
00024
00025 template <typename T, typename... Other>
00026 struct generator_choose<T, Other...>
00027 : public generator_choose<Other...> {
00028 private:
00029 typedef generator_choose<Other...> super;
00030 T generator;
00031
00032 public:
00033 generator_choose(T t, Other... other)
00034 : generator_choose<Other...>(std::forward<Other>(other)...),
00035 generator(std::forward<T>(t)) {
00036 }
00037
00038 template <typename Return,
00039 ENABLE_IF(generator_for<T, Return>),
00040 typename Ret = typename
00041 is_callable<member_get(T&, selector<Return>)>::result_type>
00042 Ret get(selector<Return> s) {
00043 return generator.get(s);
00044 }
00045
00046 template <typename Return,
00047 ENABLE_IF_NOT(generator_for<T, Return>),
00048 ENABLE_IF(generator_for<super, Return>),
00049 typename Ret = typename
00050 is_callable<member_get(super&,
00051 selector<Return>)>::result_type>
00052 Ret get(selector<Return> s...) {
00053 return this->super::get(s);
00054 }
00055 };
00056 }
00057
00063 template <typename... T>
00064 details::generator_choose<typename std::decay<T>::type...>
00065 choose(T&&... t) {
00066 return details::generator_choose<typename std::decay<T>::type...>
00067 {std::forward<T>(t)...};
00068 }
00069
00070 }
00071
00072 #endif