2012-09-08 02:50:37 +00:00
|
|
|
#ifndef _FC_UTILITY_HPP_
|
|
|
|
|
#define _FC_UTILITY_HPP_
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <new>
|
|
|
|
|
|
2012-09-10 05:48:08 +00:00
|
|
|
#define nullptr 0
|
|
|
|
|
|
2012-09-08 02:50:37 +00:00
|
|
|
typedef decltype(sizeof(int)) size_t;
|
|
|
|
|
namespace std {
|
|
|
|
|
typedef decltype(sizeof(int)) size_t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace fc {
|
|
|
|
|
template<typename T> struct remove_reference { typedef T type; };
|
|
|
|
|
template<typename T> struct remove_reference<T&> { typedef T type; };
|
|
|
|
|
template<typename T> struct remove_reference<T&&> { typedef T type; };
|
|
|
|
|
|
2012-11-09 05:31:39 +00:00
|
|
|
template<typename T> struct deduce { typedef T type; };
|
|
|
|
|
template<typename T> struct deduce<T&> { typedef T type; };
|
|
|
|
|
template<typename T> struct deduce<const T&> { typedef T type; };
|
|
|
|
|
template<typename T> struct deduce<T&&> { typedef T type; };
|
|
|
|
|
template<typename T> struct deduce<const T&&>{ typedef T type; };
|
|
|
|
|
|
2012-09-08 02:50:37 +00:00
|
|
|
template<typename T>
|
|
|
|
|
typename fc::remove_reference<T>::type&& move( T&& t ) { return static_cast<typename fc::remove_reference<T>::type&&>(t); }
|
|
|
|
|
|
|
|
|
|
template<typename T, typename U>
|
|
|
|
|
inline T&& forward( U&& u ) { return static_cast<T&&>(u); }
|
|
|
|
|
|
2012-09-15 02:47:37 +00:00
|
|
|
struct true_type { enum _value { value = 1 }; };
|
|
|
|
|
struct false_type { enum _value { value = 0 }; };
|
|
|
|
|
|
2012-09-08 02:50:37 +00:00
|
|
|
namespace detail {
|
2012-09-15 02:47:37 +00:00
|
|
|
template<typename T> fc::true_type is_class_helper(void(T::*)());
|
|
|
|
|
template<typename T> fc::false_type is_class_helper(...);
|
2012-09-08 02:50:37 +00:00
|
|
|
}
|
2012-09-15 02:47:37 +00:00
|
|
|
|
2012-09-08 02:50:37 +00:00
|
|
|
template<typename T>
|
2012-10-21 06:28:59 +00:00
|
|
|
struct is_class { typedef decltype(detail::is_class_helper<T>(0)) type; enum value_enum { value = type::value }; };
|
2012-09-08 02:50:37 +00:00
|
|
|
|
2012-09-18 03:04:42 +00:00
|
|
|
template<typename T>
|
|
|
|
|
const T& min( const T& a, const T& b ) { return a < b ? a: b; }
|
|
|
|
|
|
2012-09-08 02:50:37 +00:00
|
|
|
template<typename T>
|
|
|
|
|
void swap( T& a, T& b ) {
|
|
|
|
|
T tmp = fc::move(a);
|
|
|
|
|
a = fc::move(b);
|
|
|
|
|
b = fc::move(tmp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif // _FC_UTILITY_HPP_
|