diff options
author | Seth Moore <sethmo@google.com> | 2021-07-09 05:26:25 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-07-09 05:26:25 +0000 |
commit | d7ace4469d1ea1acefce0f0922e97d814b6970ac (patch) | |
tree | a7b0c82cc4b342d22a22e671d64980a5384e3949 | |
parent | 8ca1ad02f8e03e7e0a00cfbffb34697245d5709c (diff) | |
parent | 1b23995a6ba5df2ae499ab1a7179b07462bf34de (diff) | |
download | libcppbor-d7ace4469d1ea1acefce0f0922e97d814b6970ac.tar.gz |
Don't allow implicit conversion to Array am: b0c9795e04 am: 1b23995a6b
Original change: https://android-review.googlesource.com/c/platform/external/libcppbor/+/1753047
Change-Id: Ia7a8b4e355aa9086135422fd1e45996ab1731108
-rw-r--r-- | include/cppbor/cppbor.h | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/include/cppbor/cppbor.h b/include/cppbor/cppbor.h index b78c41f..9bad233 100644 --- a/include/cppbor/cppbor.h +++ b/include/cppbor/cppbor.h @@ -598,6 +598,13 @@ class Array : public Item { Array(Args&&... args); /** + * The above variadic constructor is disabled if sizeof(Args) != 1, so special + * case an explicit Array constructor for creating an Array with one Item. + */ + template <typename T, typename Enable> + explicit Array(T&& v); + + /** * Append a single element to the Array, of any compatible type. */ template <typename T> @@ -1039,14 +1046,21 @@ inline void map_helper(Map& map, Key&& key, Value&& value, Rest&&... rest) { } // namespace details template <typename... Args, - /* Prevent use as copy ctor */ typename = std::enable_if_t< - (sizeof...(Args)) != 1 || - !(std::is_same_v<Array, std::remove_cv_t<std::remove_reference_t<Args>>> || ...)>> + /* Prevent implicit construction with a single argument. */ + typename = std::enable_if_t<(sizeof...(Args)) != 1>> Array::Array(Args&&... args) { mEntries.reserve(sizeof...(args)); (mEntries.push_back(details::makeItem(std::forward<Args>(args))), ...); } +template <typename T, + /* Prevent use as copy constructor. */ + typename = std::enable_if_t< + !std::is_same_v<Array, std::remove_cv_t<std::remove_reference_t<T>>>>> +Array::Array(T&& v) { + mEntries.push_back(details::makeItem(std::forward<T>(v))); +} + template <typename T> Array& Array::add(T&& v) & { mEntries.push_back(details::makeItem(std::forward<T>(v))); |