X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fdynamic-inl.h;h=325060f046f400e9b0ce491136b44a1939d014a9;hb=44dcd737f7e77320d8d1380e483f93a82dc9a970;hp=8924fb3d9bff7641b10ced941fe84c532da5c7e8;hpb=178d3b45f745e50fa70c735703bfe7c4dba9ace5;p=folly.git diff --git a/folly/dynamic-inl.h b/folly/dynamic-inl.h index 8924fb3d..325060f0 100644 --- a/folly/dynamic-inl.h +++ b/folly/dynamic-inl.h @@ -1,5 +1,5 @@ /* - * Copyright 2015 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,22 +14,23 @@ * limitations under the License. */ -#ifndef FOLLY_DYNAMIC_INL_H_ -#define FOLLY_DYNAMIC_INL_H_ +#pragma once #include + #include #include -#include + #include #include +#include ////////////////////////////////////////////////////////////////////// namespace std { -template<> -struct hash< ::folly::dynamic> { +template <> +struct hash<::folly::dynamic> { size_t operator()(::folly::dynamic const& d) const { return d.hash(); } @@ -41,18 +42,35 @@ struct hash< ::folly::dynamic> { // This is a higher-order preprocessor macro to aid going from runtime // types to the compile time type system. -#define FB_DYNAMIC_APPLY(type, apply) do { \ - switch ((type)) { \ - case NULLT: apply(void*); break; \ - case ARRAY: apply(Array); break; \ - case BOOL: apply(bool); break; \ - case DOUBLE: apply(double); break; \ - case INT64: apply(int64_t); break; \ - case OBJECT: apply(ObjectImpl); break; \ - case STRING: apply(fbstring); break; \ - default: CHECK(0); abort(); \ - } \ -} while (0) +#define FB_DYNAMIC_APPLY(type, apply) \ + do { \ + switch ((type)) { \ + case NULLT: \ + apply(std::nullptr_t); \ + break; \ + case ARRAY: \ + apply(Array); \ + break; \ + case BOOL: \ + apply(bool); \ + break; \ + case DOUBLE: \ + apply(double); \ + break; \ + case INT64: \ + apply(int64_t); \ + break; \ + case OBJECT: \ + apply(ObjectImpl); \ + break; \ + case STRING: \ + apply(std::string); \ + break; \ + default: \ + CHECK(0); \ + abort(); \ + } \ + } while (0) ////////////////////////////////////////////////////////////////////// @@ -60,11 +78,20 @@ namespace folly { struct TypeError : std::runtime_error { explicit TypeError(const std::string& expected, dynamic::Type actual); - explicit TypeError(const std::string& expected, - dynamic::Type actual1, dynamic::Type actual2); - ~TypeError(); + explicit TypeError( + const std::string& expected, + dynamic::Type actual1, + dynamic::Type actual2); + ~TypeError() override; }; +[[noreturn]] void throwTypeError_( + std::string const& expected, + dynamic::Type actual); +[[noreturn]] void throwTypeError_( + std::string const& expected, + dynamic::Type actual1, + dynamic::Type actual2); ////////////////////////////////////////////////////////////////////// @@ -73,42 +100,7 @@ namespace detail { // This helper is used in destroy() to be able to run destructors on // types like "int64_t" without a compiler error. struct Destroy { - template static void destroy(T* t) { t->~T(); } - }; - - /* - * The enable_if junk here is necessary to avoid ambiguous - * conversions relating to bool and double when you implicitly - * convert an int or long to a dynamic. - */ - template struct ConversionHelper; - template - struct ConversionHelper< - T, - typename std::enable_if< - std::is_integral::value && !std::is_same::value - >::type - > { - typedef int64_t type; - }; - template - struct ConversionHelper< - T, - typename std::enable_if< - (!std::is_integral::value || std::is_same::value) && - !std::is_same::value - >::type - > { - typedef T type; - }; - template - struct ConversionHelper< - T, - typename std::enable_if< - std::is_same::value - >::type - > { - typedef void* type; + template static void destroy(T* t) { t->~T(); } }; /* @@ -116,10 +108,10 @@ namespace detail { * numbers. Just promotes to double when one of the arguments is * double, or throws if either is not a numeric type. */ - template class Op> + template