peerplays-fc/include/fc/utility.hpp

66 lines
2.1 KiB
C++
Raw Normal View History

2013-03-01 23:56:06 +00:00
#pragma once
2012-09-08 02:50:37 +00:00
#include <stdint.h>
#include <new>
#ifdef _MSC_VER
#pragma warning(disable: 4482) // nonstandard extension used enum Name::Val, standard in C++11
#define NO_RETURN __declspec(noreturn)
#else
#define NO_RETURN __attribute__((noreturn))
#endif
2014-02-06 08:22:09 +00:00
//namespace std {
// typedef decltype(sizeof(int)) size_t;
// typedef decltype(nullptr) nullptr_t;
//}
2012-09-08 02:50:37 +00:00
namespace fc {
using std::size_t;
typedef decltype(nullptr) nullptr_t;
2012-09-08 02:50:37 +00:00
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); }
struct true_type { enum _value { value = 1 }; };
struct false_type { enum _value { value = 0 }; };
2012-09-08 02:50:37 +00:00
namespace detail {
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-08 02:50:37 +00:00
template<typename T>
struct is_class { typedef decltype(detail::is_class_helper<T>(0)) type; enum value_enum { value = type::value }; };
#ifdef min
#undef min
#endif
template<typename T>
const T& min( const T& a, const T& b ) { return a < b ? a: b; }
2012-12-03 19:51:31 +00:00
}
// outside of namespace fc becuase of VC++ conflict with std::swap
2012-09-08 02:50:37 +00:00
template<typename T>
void fc_swap( T& a, T& b ) {
2012-09-08 02:50:37 +00:00
T tmp = fc::move(a);
a = fc::move(b);
b = fc::move(tmp);
}
#define LLCONST(constant) static_cast<int64_t>(constant##ll)
#define ULLCONST(constant) static_cast<uint64_t>(constant##ull)