mirror of
https://github.com/nlohmann/json.git
synced 2026-09-02 06:27:13 +00:00
Give the custom container types only the constructors the library uses
The three container types in the new tests inherited every constructor of their base with using Base::Base. That asks for more than the test needs: the library builds an object or an array by default construction, by copy or move, and -- when converting between two basic_json types or from an initializer list -- from an iterator range. Declaring those directly makes the requirement visible in the test, and keeps object types out of a corner where a compiler has to declare std::map's whole constructor set for a derived class while basic_json is still incomplete. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -30,7 +30,11 @@ template<class T, class Allocator = std::allocator<T>>
|
|||||||
class vector_without_at : public std::vector<T, Allocator>
|
class vector_without_at : public std::vector<T, Allocator>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using std::vector<T, Allocator>::vector;
|
vector_without_at() = default;
|
||||||
|
|
||||||
|
// the array of an initializer list is built from a range
|
||||||
|
template<class InputIt>
|
||||||
|
vector_without_at(InputIt first, InputIt last) : std::vector<T, Allocator>(first, last) {}
|
||||||
|
|
||||||
void at() = delete;
|
void at() = delete;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,7 +35,12 @@ template<class Key, class T, class Compare, class Allocator>
|
|||||||
struct no_key_compare_map : std::map<Key, T, Compare, Allocator>
|
struct no_key_compare_map : std::map<Key, T, Compare, Allocator>
|
||||||
{
|
{
|
||||||
using base_t = std::map<Key, T, Compare, Allocator>;
|
using base_t = std::map<Key, T, Compare, Allocator>;
|
||||||
using base_t::base_t;
|
|
||||||
|
no_key_compare_map() = default;
|
||||||
|
|
||||||
|
// converting between two basic_json types builds the object from a range
|
||||||
|
template<class InputIt>
|
||||||
|
no_key_compare_map(InputIt first, InputIt last) : base_t(first, last) {}
|
||||||
|
|
||||||
// shadows base_t::key_compare, which is a type; never defined or called
|
// shadows base_t::key_compare, which is a type; never defined or called
|
||||||
void key_compare();
|
void key_compare();
|
||||||
@@ -49,7 +54,6 @@ template<class Key, class T, class Compare, class Allocator>
|
|||||||
struct void_erase_map : std::map<Key, T, Compare, Allocator>
|
struct void_erase_map : std::map<Key, T, Compare, Allocator>
|
||||||
{
|
{
|
||||||
using base_t = std::map<Key, T, Compare, Allocator>;
|
using base_t = std::map<Key, T, Compare, Allocator>;
|
||||||
using base_t::base_t;
|
|
||||||
using iterator = typename base_t::iterator;
|
using iterator = typename base_t::iterator;
|
||||||
using base_t::erase;
|
using base_t::erase;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user