Boost type traits / enable_if -> <type_traits>

This commit is contained in:
Celtic Minstrel 2016-07-25 01:29:53 -04:00
parent 531e05af9e
commit e6b8681de8
11 changed files with 87 additions and 126 deletions

View File

@ -38,16 +38,12 @@
#include <string>
#include <utility>
#include <vector>
#include <type_traits>
#include <boost/exception/exception.hpp>
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/variant.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/add_const.hpp>
#include <boost/type_traits/is_base_of.hpp>
#include "exceptions.hpp"
#include "tstring.hpp"
#include "utils/iterable_pair.hpp"
@ -301,7 +297,7 @@ public:
attribute_value &operator=(const std::string &v);
attribute_value &operator=(const t_string &v);
template<typename T>
typename boost::enable_if<boost::is_base_of<enum_tag, T>, attribute_value &>::type operator=(const T &v)
typename std::enable_if<std::is_base_of<enum_tag, T>::value, attribute_value &>::type operator=(const T &v)
{
return operator=(T::enum_to_string(v));
}
@ -321,7 +317,7 @@ public:
TODO: Fix this in c++11 using constexpr types.
*/
template<typename T>
typename boost::enable_if<boost::is_base_of<enum_tag, T>, T>::type to_enum(const T &v) const
typename std::enable_if<std::is_base_of<enum_tag, T>::value, T>::type to_enum(const T &v) const
{
return T::string_to_enum(this->str(), v);
}
@ -346,12 +342,12 @@ public:
// These function prevent t_string creation in case of c["a"] == "b" comparisons.
// The templates are needed to prevent using these function in case of c["a"] == 0 comparisons.
template<typename T>
typename boost::enable_if<boost::is_same<const std::string, typename boost::add_const<T>::type>, bool>::type
typename std::enable_if<std::is_same<const std::string, typename std::add_const<T>::type>::value, bool>::type
friend operator==(const attribute_value &val, const T &str)
{ return val.equals(str); }
template<typename T>
typename boost::enable_if<boost::is_same<const char*, T>, bool>::type
typename std::enable_if<std::is_same<const char*, T>::value, bool>::type
friend operator==(const attribute_value &val, T str)
{ return val.equals(std::string(str)); }

View File

@ -26,7 +26,7 @@
#include "overlay.hpp"
#include "display_context.hpp"
#include <boost/utility.hpp>
#include <boost/noncopyable.hpp>
namespace editor {

View File

@ -24,7 +24,7 @@
#include "utils/functional.hpp"
#include <boost/mpl/int.hpp>
#include <boost/utility/enable_if.hpp>
#include <type_traits>
#include <map>
@ -37,6 +37,9 @@ class twidget;
namespace event
{
template<typename K, tevent E>
using has_key = boost::mpl::has_key<K, boost::mpl::int_<E>>;
struct tmessage;
/**
@ -258,7 +261,7 @@ public:
/**
* Connect a signal for callback in tset_event.
*
* The function uses some boost magic to avoid registering the wrong
* The function uses some enable_if magic to avoid registering the wrong
* function, but the common way to use this function is:
* widget->connect_signal<EVENT_ID>(
* std::bind(&tmy_dialog::my_member, this));
@ -273,8 +276,7 @@ public:
* @param position The position to place the callback.
*/
template <tevent E>
typename boost::enable_if<boost::mpl::has_key<tset_event,
boost::mpl::int_<E> > >::type
typename std::enable_if<has_key<tset_event, E>::value>::type
connect_signal(const tsignal_function& signal,
const tposition position = back_child)
{
@ -292,8 +294,7 @@ public:
* was added in front or back.)
*/
template <tevent E>
typename boost::enable_if<boost::mpl::has_key<tset_event,
boost::mpl::int_<E> > >::type
typename std::enable_if<has_key<tset_event, E>::value>::type
disconnect_signal(const tsignal_function& signal,
const tposition position = back_child)
{
@ -308,8 +309,7 @@ public:
* @param position The position to place the callback.
*/
template <tevent E>
typename boost::enable_if<boost::mpl::has_key<tset_event_mouse,
boost::mpl::int_<E> > >::type
typename std::enable_if<has_key<tset_event_mouse, E>::value>::type
connect_signal(const tsignal_mouse_function& signal,
const tposition position = back_child)
{
@ -327,8 +327,7 @@ public:
* was added in front or back.)
*/
template <tevent E>
typename boost::enable_if<boost::mpl::has_key<tset_event_mouse,
boost::mpl::int_<E> > >::type
typename std::enable_if<has_key<tset_event_mouse, E>::value>::type
disconnect_signal(const tsignal_mouse_function& signal,
const tposition position = back_child)
{
@ -343,8 +342,7 @@ public:
* @param position The position to place the callback.
*/
template <tevent E>
typename boost::enable_if<boost::mpl::has_key<tset_event_keyboard,
boost::mpl::int_<E> > >::type
typename std::enable_if<has_key<tset_event_keyboard, E>::value>::type
connect_signal(const tsignal_keyboard_function& signal,
const tposition position = back_child)
{
@ -362,8 +360,7 @@ public:
* was added in front or back.)
*/
template <tevent E>
typename boost::enable_if<boost::mpl::has_key<tset_event_keyboard,
boost::mpl::int_<E> > >::type
typename std::enable_if<has_key<tset_event_keyboard, E>::value>::type
disconnect_signal(const tsignal_keyboard_function& signal,
const tposition position = back_child)
{
@ -381,8 +378,7 @@ public:
* and shouldn't be used.
*/
template <tevent E>
typename boost::enable_if<boost::mpl::has_key<tset_event_notification,
boost::mpl::int_<E> > >::type
typename std::enable_if<has_key<tset_event_notification, E>::value>::type
connect_signal(const tsignal_notification_function& signal,
const tposition position = back_child)
{
@ -405,8 +401,7 @@ public:
* front_pre_child)
*/
template <tevent E>
typename boost::enable_if<boost::mpl::has_key<tset_event_notification,
boost::mpl::int_<E> > >::type
typename std::enable_if<has_key<tset_event_notification, E>::value>::type
disconnect_signal(const tsignal_notification_function& signal,
const tposition position = back_child)
{
@ -424,8 +419,7 @@ public:
* and shouldn't be used.
*/
template <tevent E>
typename boost::enable_if<boost::mpl::has_key<tset_event_message,
boost::mpl::int_<E> > >::type
typename std::enable_if<has_key<tset_event_message, E>::value>::type
connect_signal(const tsignal_message_function& signal,
const tposition position = back_child)
{
@ -448,8 +442,7 @@ public:
* front_pre_child)
*/
template <tevent E>
typename boost::enable_if<boost::mpl::has_key<tset_event_message,
boost::mpl::int_<E> > >::type
typename std::enable_if<has_key<tset_event_message, E>::value>::type
disconnect_signal(const tsignal_message_function& signal,
const tposition position = back_child)
{

View File

@ -20,8 +20,6 @@
#include <pango/pango-layout.h>
#include <boost/cstdint.hpp>
#include <boost/type_traits.hpp>
#include <boost/utility/enable_if.hpp>
#include <string>

View File

@ -55,9 +55,8 @@
#include <cstdlib>
#include <string>
#include <sstream>
#include <type_traits>
#include <boost/mpl/set.hpp>
#include <boost/type_traits.hpp>
#include <boost/utility/enable_if.hpp>
#define DEBUG_THROW(id)
#endif
@ -145,8 +144,8 @@ struct tlexical_cast<
std::string
, From
, void
, typename boost::enable_if<boost::is_integral<
typename boost::remove_pointer<From>::type> >::type
, typename std::enable_if<std::is_integral<
typename std::remove_pointer<From>::type>::value >::type
>
{
std::string operator()(From value)
@ -171,8 +170,8 @@ struct tlexical_cast<
long long
, From
, void
, typename boost::enable_if<boost::mpl::has_key<boost::mpl::set<
char*, const char*> , From> >::type
, typename std::enable_if<boost::mpl::has_key<boost::mpl::set<
char*, const char*> , From>::value >::type
>
{
long long operator()(From value)
@ -220,9 +219,9 @@ template <class To, class From>
struct tlexical_cast<
To
, From
, typename boost::enable_if<boost::is_signed<To> >::type
, typename boost::enable_if<boost::mpl::has_key<boost::mpl::set<
char*, const char*> , From> >::type
, typename std::enable_if<std::is_signed<To>::value >::type
, typename std::enable_if<boost::mpl::has_key<boost::mpl::set<
char*, const char*> , From>::value >::type
>
{
To operator()(From value)
@ -249,7 +248,7 @@ template <class To>
struct tlexical_cast<
To
, std::string
, typename boost::enable_if<boost::is_signed<To> >::type
, typename std::enable_if<std::is_signed<To>::value >::type
>
{
To operator()(const std::string& value)
@ -272,8 +271,8 @@ struct tlexical_cast<
unsigned long long
, From
, void
, typename boost::enable_if<boost::mpl::has_key<boost::mpl::set<
char*, const char*> , From> >::type
, typename std::enable_if<boost::mpl::has_key<boost::mpl::set<
char*, const char*> , From>::value >::type
>
{
long long operator()(From value)
@ -322,9 +321,9 @@ template <class To, class From>
struct tlexical_cast<
To
, From
, typename boost::enable_if<boost::is_unsigned<To> >::type
, typename boost::enable_if<boost::mpl::has_key<boost::mpl::set<
char*, const char*> , From> >::type
, typename std::enable_if<std::is_unsigned<To>::value >::type
, typename std::enable_if<boost::mpl::has_key<boost::mpl::set<
char*, const char*> , From>::value >::type
>
{
To operator()(From value)
@ -351,7 +350,7 @@ template <class To>
struct tlexical_cast<
To
, std::string
, typename boost::enable_if<boost::is_unsigned<To> >::type
, typename std::enable_if<std::is_unsigned<To>::value >::type
>
{
To operator()(const std::string& value)

View File

@ -2,7 +2,7 @@
#include "scripting/lua_common.hpp"
#include <boost/type_traits.hpp>
#include <type_traits>
#include <boost/mpl/not.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/has_xxx.hpp>
@ -68,48 +68,55 @@ namespace lua_check_impl
template<typename T>
struct remove_constref
{
typedef typename boost::remove_const<typename boost::remove_reference<typename boost::remove_const<T>::type>::type>::type type;
typedef typename std::remove_const<typename std::remove_reference<typename std::remove_const<T>::type>::type>::type type;
};
//std::string
template<typename T>
typename boost::enable_if<typename boost::is_same<T, std::string>::type, std::string>::type lua_check(lua_State *L, int n)
typename std::enable_if<std::is_same<T, std::string>::value, std::string>::type
lua_check(lua_State *L, int n)
{
return luaL_checkstring(L, n);
}
template<typename T>
typename boost::enable_if<typename boost::is_same<T, std::string>::type, void>::type lua_push(lua_State *L, const T& val)
typename std::enable_if<std::is_same<T, std::string>::value, void>::type
lua_push(lua_State *L, const T& val)
{
lua_pushlstring(L, val.c_str(), val.size());
}
//config
template<typename T>
typename boost::enable_if<typename boost::is_same<T, config>::type, config>::type lua_check(lua_State *L, int n)
typename std::enable_if<std::is_same<T, config>::value, config>::type
lua_check(lua_State *L, int n)
{
return luaW_checkconfig(L, n);
}
template<typename T>
typename boost::enable_if<typename boost::is_same<T, config>::type, void>::type lua_push(lua_State *L, const config& val)
typename std::enable_if<std::is_same<T, config>::value, void>::type
lua_push(lua_State *L, const config& val)
{
luaW_pushconfig(L, val);
}
//location
template<typename T>
typename boost::enable_if<typename boost::is_same<T, map_location>::type, map_location>::type lua_check(lua_State *L, int n)
typename std::enable_if<std::is_same<T, map_location>::value, map_location>::type
lua_check(lua_State *L, int n)
{
return luaW_checklocation(L, n);
}
template<typename T>
typename boost::enable_if<typename boost::is_same<T, map_location>::type, void>::type lua_push(lua_State *L, const map_location& val)
typename std::enable_if<std::is_same<T, map_location>::value, void>::type
lua_push(lua_State *L, const map_location& val)
{
luaW_pushlocation(L, val);
}
//enums generated by MAKE_ENUM
template<typename T>
typename boost::enable_if<boost::is_base_of<enum_tag, T>, T>::type lua_check(lua_State *L, int n)
typename std::enable_if<std::is_base_of<enum_tag, T>::value, T>::type
lua_check(lua_State *L, int n)
{
T val;
std::string str = lua_check_impl::lua_check<std::string>(L, n);
@ -120,68 +127,65 @@ namespace lua_check_impl
return val;
}
template<typename T>
typename boost::enable_if<boost::is_base_of<enum_tag, T>, void>::type lua_push(lua_State *L, T val)
typename std::enable_if<std::is_base_of<enum_tag, T>::value, void>::type
lua_push(lua_State *L, T val)
{
lua_check_impl::lua_push(L, val.to_string());
}
//t_string
template<typename T>
typename boost::enable_if<typename boost::is_same<T, t_string>::type, t_string>::type lua_check(lua_State *L, int n)
typename std::enable_if<std::is_same<T, t_string>::value, t_string>::type
lua_check(lua_State *L, int n)
{
return luaW_checktstring(L, n);
}
template<typename T>
typename boost::enable_if<typename boost::is_same<T, t_string>::type, void>::type lua_push(lua_State *L, const t_string& val)
typename std::enable_if<std::is_same<T, t_string>::value, void>::type
lua_push(lua_State *L, const t_string& val)
{
luaW_pushtstring(L, val);
}
//bool
template<typename T>
typename boost::enable_if<typename boost::is_same<T, bool>::type, bool>::type lua_check(lua_State *L, int n)
typename std::enable_if<std::is_same<T, bool>::value, bool>::type
lua_check(lua_State *L, int n)
{
return luaW_toboolean(L, n);
}
template<typename T>
typename boost::enable_if<typename boost::is_same<T, bool>::type, void>::type lua_push(lua_State *L, bool val)
typename std::enable_if<std::is_same<T, bool>::value, void>::type
lua_push(lua_State *L, bool val)
{
lua_pushboolean(L, val);
}
//double, float
template<typename T>
typename boost::enable_if<boost::is_float<T>, T>::type lua_check(lua_State *L, int n)
typename std::enable_if<std::is_floating_point<T>::value, T>::type
lua_check(lua_State *L, int n)
{
return luaL_checknumber(L, n);
}
template<typename T>
typename boost::enable_if<boost::is_float<T>, void>::type lua_push(lua_State *L, T val)
typename std::enable_if<std::is_floating_point<T>::value, void>::type
lua_push(lua_State *L, T val)
{
lua_pushnumber(L, val);
}
//integer types
template<typename T>
typename boost::enable_if<
boost::mpl::and_<
boost::is_integral<T>,
boost::mpl::not_<typename boost::is_same<T, bool>::type>
>,
T
>::type lua_check(lua_State *L, int n)
typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, bool>::value, T>::type
lua_check(lua_State *L, int n)
{
return luaL_checkinteger(L, n);
}
template<typename T>
typename boost::enable_if<
boost::mpl::and_<
boost::is_integral<T>,
boost::mpl::not_<typename boost::is_same<T, bool>::type>
>,
void
>::type lua_push(lua_State *L, T val)
typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, bool>::value, void>::type
lua_push(lua_State *L, T val)
{
lua_pushnumber(L, val);
}
@ -189,13 +193,7 @@ namespace lua_check_impl
//std::pair
//Not sure if the not_<is_const> is required; only (maybe) if std::map matches is_container
template<typename T>
typename boost::enable_if<
typename boost::mpl::and_<
typename is_pair<T>::type,
typename boost::mpl::not_<typename boost::is_const<typename T::first_type> >::type
>::type,
T
>::type
typename std::enable_if<is_pair<T>::value && !std::is_const<typename T::first_type>::value, T>::type
lua_check(lua_State *L, int n)
{
T result;
@ -209,13 +207,7 @@ namespace lua_check_impl
return result;
}
template<typename T>
typename boost::enable_if<
typename boost::mpl::and_<
typename is_pair<T>::type,
typename boost::mpl::not_<typename boost::is_const<typename T::first_type> >::type
>::type,
void
>::type
typename std::enable_if<is_pair<T>::value && !std::is_const<typename T::first_type>::value, void>::type
lua_push(lua_State *L, const T& val)
{
lua_newtable(L);
@ -227,13 +219,7 @@ namespace lua_check_impl
//std::vector and similar but not std::string
template<typename T>
typename boost::enable_if<
typename boost::mpl::and_<
typename is_container<T>::type,
typename boost::mpl::not_<typename boost::is_same<T, std::string> >::type
>::type,
T
>::type
typename std::enable_if<is_container<T>::value && !std::is_same<T, std::string>::value, T>::type
lua_check(lua_State * L, int n)
{
if (lua_istable(L, n))
@ -261,15 +247,11 @@ namespace lua_check_impl
#endif
#endif
//also accepts things like std::vector<int>() | boost::adaptors::transformed(..)
//also accepts things like std::vector<int>() | std::adaptors::transformed(..)
template<typename T>
typename boost::enable_if<
typename boost::mpl::and_<
typename is_container<T>::type,
typename boost::mpl::not_<typename boost::is_same<T, std::string> >::type,
typename boost::mpl::not_<typename is_map<T>::type >::type
>::type,
void
typename std::enable_if<
is_container<T>::value && !std::is_same<T, std::string>::value && !is_map<T>::value
, void
>::type
lua_push(lua_State * L, const T& list )
{
@ -286,10 +268,7 @@ namespace lua_check_impl
//accepts std::map TODO: add a check function for that
template<typename T>
typename boost::enable_if<
typename is_map<T>::type,
void
>::type
typename std::enable_if<is_map<T>::value, void>::type
lua_push(lua_State * L, const T& map )
{
lua_newtable(L);

View File

@ -17,8 +17,6 @@
#include "ucs4_convert_impl.hpp"
#include <iostream> //for std::cerr
#include <iterator>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_arithmetic.hpp>
namespace ucs4_convert_impl
{

View File

@ -14,7 +14,7 @@
#include "room.hpp"
#include <boost/utility.hpp>
#include <boost/noncopyable.hpp>
class config;

View File

@ -49,7 +49,6 @@
#include "utils/functional.hpp"
#include <boost/utility.hpp>
#include <algorithm>
#include <cassert>
#include <cerrno>

View File

@ -15,8 +15,7 @@
#ifndef UTILS_CONST_CLONE_HPP_INCLUDED
#define UTILS_CONST_CLONE_HPP_INCLUDED
#include <boost/type_traits.hpp>
#include <boost/utility/enable_if.hpp>
#include <type_traits>
namespace utils {
@ -37,7 +36,7 @@ namespace utils {
* a cv-qualifier, although @c volatile has no
* effect.
* @tparam E The enable parameter for
* @ref boost::enable_if.
* @ref std::enable_if.
*/
template<
class D
@ -68,12 +67,12 @@ template<
struct tconst_clone<
D
, S
, typename boost::enable_if<
boost::is_const<
typename boost::remove_pointer<
typename boost::remove_reference<S>::type
, typename std::enable_if<
std::is_const<
typename std::remove_pointer<
typename std::remove_reference<S>::type
>::type
>
>::value
>::type
>
{

View File

@ -19,7 +19,7 @@
#include "lua_jailbreak_exception.hpp"
#include <memory>
#include <boost/utility.hpp>
#include <boost/noncopyable.hpp>
#include "sdl/window.hpp"