Improve bind, placeholder, and function support

This commit is contained in:
Vinnie Falco
2013-06-27 17:38:40 -07:00
parent 98ac0697a9
commit 9328e6fdec
3 changed files with 325 additions and 97 deletions

View File

@@ -44,6 +44,11 @@
#define BEAST_USE_BOOST 0
#endif
// Choose one to override default for platform
//#define BEAST_BIND_USES_STD 1
//#define BEAST_BIND_USES_TR1 1
//#define BEAST_BIND_USES_BOOST 1
#ifndef BEAST_USE_LEAKCHECKED
#define BEAST_USE_LEAKCHECKED BEAST_CHECK_MEMORY_LEAKS
#endif

View File

@@ -241,53 +241,13 @@
to append the necessary macros into their AppConfig.h.
*/
#ifndef BEAST_USE_BOOST
#define BEAST_USE_BOOST 0
#define BEAST_USE_BOOST 0
#endif
#ifndef BEAST_USE_LEAKCHECKED
#define BEAST_USE_LEAKCHECKED BEAST_CHECK_MEMORY_LEAKS
#endif
/* Get this early so we can use it. */
#include "../beast_core/system/beast_TargetPlatform.h"
#if BEAST_USE_BOOST
#include <boost/thread/tss.hpp>
#endif
#if BEAST_MSVC
# include <crtdbg.h>
# include <functional>
#elif BEAST_IOS
# if BEAST_USE_BOOST
# include <boost/bind.hpp>
# include <boost/function.hpp>
# else
# include <ciso646> // detect std::lib
# if _LIBCPP_VERSION // libc++
# include <functional>
# else // libstdc++ (GNU)
# include <tr1/functional>
# endif
# endif
#elif BEAST_MAC
# include <ciso646> // detect std::lib
# if _LIBCPP_VERSION // libc++
# include <functional>
# else // libstdc++ (GNU)
# include <tr1/functional>
# endif
#elif BEAST_LINUX || BEAST_BSD
# include <tr1/functional>
#else
# error Unknown platform!
#endif
#include <algorithm>
#include <cfloat>
#include <cmath>
@@ -321,6 +281,47 @@
#include <stdlib.h>
#include <string.h>
/* Get this early so we can use it. */
#include "../beast_core/system/beast_TargetPlatform.h"
//------------------------------------------------------------------------------
// Choose a source of bind, placeholders, and function
#if !BEAST_BIND_USES_STD && !BEAST_BIND_USES_TR1 && !BEAST_BIND_USES_BOOST
# if BEAST_MSVC
# define BEAST_BIND_USES_STD 1
# elif BEAST_IOS || BEAST_MAC
# include <ciso646> // detect version of std::lib
# if BEAST_IOS && BEAST_USE_BOOST // Work-around for iOS bugs with bind.
# define BEAST_BIND_USES_BOOST 1
# elif _LIBCPP_VERSION // libc++
# define BEAST_BIND_USES_STD 1
# else // libstdc++ (GNU)
# define BEAST_BIND_USES_TR1 1
# endif
# elif BEAST_LINUX || BEAST_BSD
# define BEAST_BIND_USES_TR1 1
# else
# define BEAST_BIND_USES_STD 1
# endif
#endif
#if BEAST_BIND_USES_STD
# include <functional>
#elif BEAST_BIND_USES_TR1
# include <tr1/functional>
#elif BEAST_BIND_USES_BOOST
# include <boost/bind.hpp>
# include <boost/function.hpp>
#endif
//------------------------------------------------------------------------------
#if BEAST_USE_BOOST
#include <boost/thread/tss.hpp>
#endif
#ifdef _CRTDBG_MAP_ALLOC
#error "MSVC C Runtime Debug Macros not supported"
#endif

View File

@@ -22,63 +22,13 @@
/* Brings functional support into our namespace, based on environment.
*/
#if BEAST_MSVC
// Visual Studio has these in std.
using std::ref;
using std::bind;
using std::function;
using std::placeholders::_1;
using std::placeholders::_2;
#elif BEAST_IOS
#if BEAST_USE_BOOST
/* If boost is activated, use it. This works
around a bug with the iOS implementation of bind.
*/
using boost::ref
using boost::bind;
using boost::function;
using ::_1;
using ::_2;
#else
#if _LIBCPP_VERSION // libc++
using std::ref;
using std::bind;
using std::function;
using std::placeholders::_1;
using std::placeholders::_2;
#else // libstdc++ (GNU)
using std::tr1::ref;
using std::tr1::bind;
using std::tr1::function;
using std::tr1::placeholders::_1;
using std::tr1::placeholders::_2;
#endif
#endif
#elif BEAST_MAC
#if _LIBCPP_VERSION // libc++
using std::ref;
using std::bind;
using std::function;
using std::placeholders::_1;
using std::placeholders::_2;
#else // libstdc++ (GNU)
using std::tr1::ref;
using std::tr1::bind;
using std::tr1::function;
using std::tr1::placeholders::_1;
using std::tr1::placeholders::_2;
#endif
#elif BEAST_LINUX || BEAST_BSD
using std::tr1::bind;
using std::tr1::placeholders::_1;
using std::tr1::placeholders::_2;
#else
#error Unknown platform in beast_Bind.h
#ifndef BEAST_BIND_PLACEHOLDERS_N
# if BEAST_MSVC && BEAST_BIND_USES_STD
# define BEAST_BIND_PLACEHOLDERS_N 20 // Visual Studio 2012
# else
# define BEAST_BIND_PLACEHOLDERS_N 8 // Seems a reasonable number
# endif
#endif
/** Max number of arguments to bind, total.
@@ -93,4 +43,276 @@ using std::tr1::placeholders::_2;
# define BEAST_VARIADIC_MAX 9
#endif
//------------------------------------------------------------------------------
#if BEAST_BIND_USES_STD
using std::ref;
using std::bind;
using std::function;
#if BEAST_BIND_PLACEHOLDERS_N >= 1
using std::placeholders::_1;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 2
using std::placeholders::_2;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 3
using std::placeholders::_3;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 4
using std::placeholders::_4;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 5
using std::placeholders::_5;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 6
using std::placeholders::_6;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 7
using std::placeholders::_7;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 8
using std::placeholders::_8;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 9
using std::placeholders::_9;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 10
using std::placeholders::_10;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 11
using std::placeholders::_11;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 12
using std::placeholders::_12;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 13
using std::placeholders::_13;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 14
using std::placeholders::_14;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 15
using std::placeholders::_15;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 16
using std::placeholders::_16;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 17
using std::placeholders::_17;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 18
using std::placeholders::_18;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 19
using std::placeholders::_19;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 20
using std::placeholders::_20;
#endif
//------------------------------------------------------------------------------
#elif BEAST_BIND_USES_TR1
using std::tr1::ref;
using std::tr1::bind;
using std::tr1::function;
#if BEAST_BIND_PLACEHOLDERS_N >= 1
using std::tr1::placeholders::_1;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 2
using std::tr1::placeholders::_2;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 3
using std::tr1::placeholders::_3;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 4
using std::tr1::placeholders::_4;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 5
using std::tr1::placeholders::_5;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 6
using std::tr1::placeholders::_6;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 7
using std::tr1::placeholders::_7;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 8
using std::tr1::placeholders::_8;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 9
using std::tr1::placeholders::_9;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 10
using std::tr1::placeholders::_10;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 11
using std::tr1::placeholders::_11;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 12
using std::tr1::placeholders::_12;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 13
using std::tr1::placeholders::_13;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 14
using std::tr1::placeholders::_14;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 15
using std::tr1::placeholders::_15;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 16
using std::tr1::placeholders::_16;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 17
using std::tr1::placeholders::_17;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 18
using std::tr1::placeholders::_18;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 19
using std::tr1::placeholders::_19;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 20
using std::tr1::placeholders::_20;
#endif
//------------------------------------------------------------------------------
#elif BEAST_BIND_USES_BOOST
using boost::ref;
using boost::bind;
using boost::function;
#if BEAST_BIND_PLACEHOLDERS_N >= 1
using ::_1;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 2
using ::_2;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 3
using ::_3;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 4
using ::_4;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 5
using ::_5;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 6
using ::_6;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 7
using ::_7;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 8
using ::_8;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 9
using ::_9;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 10
using ::_10;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 11
using ::_11;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 12
using ::_12;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 13
using ::_13;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 14
using ::_14;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 15
using ::_15;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 16
using ::_16;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 17
using ::_17;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 18
using ::_18;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 19
using ::_19;
#endif
#if BEAST_BIND_PLACEHOLDERS_N >= 20
using ::_20;
#endif
//------------------------------------------------------------------------------
#else
#error Unknown bind source in beast_Bind.h
#endif
#endif