Commit 359eb495 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Use C++ v.s. PP to handle libcpp in dynamic ctor

Summary: [Folly] Use C++ v.s. PP to handle libcpp in `dynamic` ctor taking `std::vector<bool>::const_reference`.

Reviewed By: shixiao

Differential Revision: D9027115

fbshipit-source-id: 94de4260d1d40ac450c37d3803994d436adcf06e
parent b3aee940
...@@ -364,10 +364,8 @@ struct dynamic::NumericTypeHelper<double> { ...@@ -364,10 +364,8 @@ struct dynamic::NumericTypeHelper<double> {
inline dynamic::dynamic(std::vector<bool>::reference b) inline dynamic::dynamic(std::vector<bool>::reference b)
: dynamic(static_cast<bool>(b)) {} : dynamic(static_cast<bool>(b)) {}
#if defined(_LIBCPP_VERSION) inline dynamic::dynamic(VectorBoolConstRefCtorType b)
inline dynamic::dynamic(std::vector<bool>::const_reference b)
: dynamic(static_cast<bool>(b)) {} : dynamic(static_cast<bool>(b)) {}
#endif
template < template <
class T, class T,
......
...@@ -100,6 +100,19 @@ struct dynamic : private boost::operators<dynamic> { ...@@ -100,6 +100,19 @@ struct dynamic : private boost::operators<dynamic> {
private: private:
typedef std::vector<dynamic> Array; typedef std::vector<dynamic> Array;
/*
* Violating spec, std::vector<bool>::const_reference is not bool in libcpp:
* http://howardhinnant.github.io/onvectorbool.html
*
* This is used to add a public ctor which is only enabled under libcpp taking
* std::vector<bool>::const_reference without using the preprocessor.
*/
struct VectorBoolConstRefFake : std::false_type {};
using VectorBoolConstRefCtorType = std::conditional_t<
std::is_same<std::vector<bool>::const_reference, bool>::value,
VectorBoolConstRefFake,
std::vector<bool>::const_reference>;
public: public:
typedef Array::iterator iterator; typedef Array::iterator iterator;
typedef Array::const_iterator const_iterator; typedef Array::const_iterator const_iterator;
...@@ -177,14 +190,9 @@ struct dynamic : private boost::operators<dynamic> { ...@@ -177,14 +190,9 @@ struct dynamic : private boost::operators<dynamic> {
* bool. Calling a function f(dynamic) with f(v[idx]) would require a double * bool. Calling a function f(dynamic) with f(v[idx]) would require a double
* implicit conversion (reference -> bool -> dynamic) which is not allowed, * implicit conversion (reference -> bool -> dynamic) which is not allowed,
* hence we explicitly accept the reference proxy. * hence we explicitly accept the reference proxy.
*
* std::vector<bool>::const_reference is not bool in libcpp:
* http://howardhinnant.github.io/onvectorbool.html
*/ */
/* implicit */ dynamic(std::vector<bool>::reference val); /* implicit */ dynamic(std::vector<bool>::reference val);
#if defined(_LIBCPP_VERSION) /* implicit */ dynamic(VectorBoolConstRefCtorType val);
/* implicit */ dynamic(std::vector<bool>::const_reference val);
#endif
/* /*
* Create a dynamic that is an array of the values from the supplied * Create a dynamic that is an array of the values from the supplied
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment