Skip to content

Commit

Permalink
add a macro for has_xxx types
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo Delrieu committed Nov 18, 2016
1 parent e23bb39 commit d9a7493
Showing 1 changed file with 17 additions and 49 deletions.
66 changes: 17 additions & 49 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,57 +144,25 @@ namespace nlohmann
@sa http://stackoverflow.com/a/7728728/266378
@since version 1.0.0, overworked in version 2.0.6
*/
template <typename T> struct has_mapped_type
{
private:
template <typename U, typename = typename U::mapped_type>
static int detect(U &&);

static void detect(...);

public:
static constexpr bool value =
std::is_integral<decltype(detect(std::declval<T>()))>::value;
};

template<typename T>
struct has_key_type
{
private:
template <typename U, typename = typename U::key_type>
static int detect(U&&);

static void detect(...);
public:
static constexpr bool value =
std::is_integral<decltype(detect(std::declval<T>()))>::value;
};

template<typename T>
struct has_value_type
{
private:
template <typename U, typename = typename U::value_type>
static int detect(U&&);

static void detect(...);
public:
static constexpr bool value =
std::is_integral<decltype(detect(std::declval<T>()))>::value;
};
#define NLOHMANN_JSON_HAS_HELPER(type) \
template <typename T> struct has_##type { \
private: \
template <typename U, typename = typename U::type> \
static int detect(U &&); \
\
static void detect(...); \
\
public: \
static constexpr bool value = \
std::is_integral<decltype(detect(std::declval<T>()))>::value; \
};

template<typename T>
struct has_iterator
{
private:
template <typename U, typename = typename U::iterator>
static int detect(U&&);
NLOHMANN_JSON_HAS_HELPER(mapped_type)
NLOHMANN_JSON_HAS_HELPER(key_type)
NLOHMANN_JSON_HAS_HELPER(value_type)
NLOHMANN_JSON_HAS_HELPER(iterator)

static void detect(...);
public:
static constexpr bool value =
std::is_integral<decltype(detect(std::declval<T>()))>::value;
};
#undef NLOHMANN_JSON_HAS_HELPER

template <bool B, class RealType, class CompatibleObjectType>
struct is_compatible_object_type_impl : std::false_type {};
Expand Down

0 comments on commit d9a7493

Please sign in to comment.