wrappers/members.hh

00001 // This file is a part of Catsfoot.
00002 // Copyright (C) 2011  Uni Research
00003 // Copyright (C) 2011  Valentin David
00004 //
00005 // This program is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser Public License
00016 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 #ifndef __MEMBERS_HH
00019 # define __MEMBERS_HH
00020 
00021 # include <utility>
00022 # include "../type_traits/always_false.hh"
00023 
00026 
00036 # define DEF_MEMBER_WRAPPER(X...)                             \
00037   struct member_##X {                                         \
00038     template <typename T, typename... U,                      \
00039               typename Ret =                                  \
00040               decltype(std::declval<T>()                      \
00041                        .X(std::declval<U>()...))>             \
00042     Ret operator()(T&& t, U&&... u...) const {                \
00043       return std::forward<T>(t).X(std::forward<U>(u)...);     \
00044     }                                                         \
00045   };
00046 
00047 
00057 # define DEF_STATIC_MEMBER_WRAPPER(X...)                \
00058   template <typename T>                                 \
00059   struct static_member_##X {                            \
00060     template <typename... U,                            \
00061               typename Ret =                            \
00062               decltype(T::X(std::declval<U>()...))>     \
00063     Ret operator()(U&&... u...) const {                 \
00064       return T::X(std::forward<U>(u)...);               \
00065     }                                                   \
00066   };
00067 
00069 # define DEF_FUNCTION_WRAPPER(X...)                             \
00070   struct function_##X {                                         \
00071     template <typename... U,                                    \
00072               typename Ret =                                    \
00073               decltype(X(std::declval<U>()...))>                \
00074     Ret operator()(U&&... u...) const {                         \
00075       return X(std::forward<U>(u)...);                          \
00076     }                                                           \
00077   };
00078 
00080 
00081 #endif