From bcfdfec8bac88f0461a90a35c045dd7c3bef34c8 Mon Sep 17 00:00:00 2001 From: Chris Fretz Date: Sun, 1 Mar 2020 01:28:48 -0500 Subject: [PATCH] Fixed an overload constraint issue in dart::object --- include/dart.h | 93 +++++++++++++++++++++++++++++++++++-- include/dart/api.tcc | 5 ++ include/dart/buffer/api.tcc | 5 ++ include/dart/heap/api.tcc | 5 ++ include/dart/object.tcc | 18 +++++++ include/dart/packet/api.tcc | 20 ++++++++ 6 files changed, 142 insertions(+), 4 deletions(-) diff --git a/include/dart.h b/include/dart.h index b688cec..946aad8 100644 --- a/include/dart.h +++ b/include/dart.h @@ -231,6 +231,24 @@ namespace dart { > explicit basic_object(Arg&& arg); + /** + * @brief + * Constructor allows an existing packet instance to be wrapped + * under the strongly typed API. + * + * @details + * If the passed packet is not an object, will throw an exception. + */ + template , + Object + >::value + >* EnableIf = nullptr + > + explicit basic_object(Arg&& arg); + /** * @brief * Function is responsible for forwarding any constructors @@ -258,6 +276,11 @@ namespace dart { Arg, Object >::value + && + !std::is_same< + std::decay_t, + Object + >::value >* EnableIf = nullptr > basic_object(Arg&& arg); @@ -4781,6 +4804,16 @@ namespace dart { > explicit basic_null(basic_null const&) {} + /** + * @brief + * Constructor allows an existing packet instance to be wrapped + * under the strongly typed API. + * + * @details + * If the passed packet is not a null, will throw an exception. + */ + explicit basic_null(Null const& null); + /** * @brief * Converting constructor to allow interoperability between underlying @@ -5434,13 +5467,21 @@ namespace dart { operator view() const& noexcept; operator view() && = delete; + /** + * @brief + * Conversion operator to finalized type + */ + explicit operator basic_buffer() const; + /** * @brief * Generic conversion operator. */ template ::value + !detail::is_dart_type::value + && + !detail::is_wrapper_type::value && convert::is_castable::value > @@ -5453,7 +5494,9 @@ namespace dart { */ template ::value + !detail::is_dart_type::value + && + !detail::is_wrapper_type::value && convert::is_castable::value > @@ -8270,13 +8313,21 @@ namespace dart { operator view() const& noexcept; operator view() && = delete; + /** + * @brief + * Explicit conversion to non-finalized type + */ + explicit operator basic_heap() const; + /** * @brief * Generic conversion operator. */ template ::value + !detail::is_dart_type::value + && + !detail::is_wrapper_type::value && convert::is_castable::value > @@ -8289,7 +8340,9 @@ namespace dart { */ template ::value + !detail::is_dart_type::value + && + !detail::is_wrapper_type::value && convert::is_castable::value > @@ -10613,12 +10666,40 @@ namespace dart { operator view() const& noexcept; operator view() && = delete; + /** + * @brief + * Explicit conversion to non-finalized API. + */ + explicit operator basic_heap() const&; + + /** + * @brief + * Explicit conversion to non-finalized API. + */ + explicit operator basic_heap() &&; + + /** + * @brief + * Explicit conversion to finalized API. + */ + explicit operator basic_buffer() const&; + + /** + * @brief + * Explicit conversion to non-finalized API. + */ + explicit operator basic_buffer() &&; + /** * @brief * Generic conversion operator. */ template ::value + && + !detail::is_wrapper_type::value + && convert::is_castable::value > > @@ -10630,6 +10711,10 @@ namespace dart { */ template ::value + && + !detail::is_wrapper_type::value + && convert::is_castable::value > > diff --git a/include/dart/api.tcc b/include/dart/api.tcc index b9abf53..a64188e 100644 --- a/include/dart/api.tcc +++ b/include/dart/api.tcc @@ -13,6 +13,11 @@ namespace dart { + template + basic_null::basic_null(Null const& null) { + if (!null.is_null()) throw type_error("dart::packet::null can only be constructed as a null"); + } + template template basic_object& basic_object::operator =(std::map const& map) & { diff --git a/include/dart/buffer/api.tcc b/include/dart/buffer/api.tcc index 52cf870..b116352 100644 --- a/include/dart/buffer/api.tcc +++ b/include/dart/buffer/api.tcc @@ -60,6 +60,11 @@ namespace dart { return tmp; } + template