Skip to content

Conversion from vector<bool> to json fails to build #494

Description

@landler

The following code:

#include "json.hpp"
#include <vector>
using nlohmann::json;

int main() {
	std::vector<bool> boolVector;
	json j;
	j["bool_vector"] = boolVector;
};

Fails to compile on os x (clang-800.0.42.1) when built like this:
clang++ -std=c++11 -c main.cpp

Substituting vector with another container (like list) compiles ok.

This also compiles fine on a linux system (I don't have the version info available, will update if necessary).

Am I missing some compiler params / something else or is this a problem with the library?

The full compilation error is below:

In file included from main.cpp:1:
./json.hpp:835:9: error: static_assert failed "could not find to_json() method in T's namespace"
        static_assert(sizeof(BasicJsonType) == 0,
        ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~
./json.hpp:844:16: note: in instantiation of function template specialization 'nlohmann::detail::to_json_fn::call<nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long,
      unsigned long long, double, std::allocator, adl_serializer>, std::__1::__bit_const_reference<std::__1::vector<bool, std::__1::allocator<bool> > > >' requested here
        return call(j, std::forward<T>(val), priority_tag<1> {});
               ^
./json.hpp:934:9: note: in instantiation of function template specialization 'nlohmann::detail::to_json_fn::operator()<nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long,
      unsigned long long, double, std::allocator, adl_serializer>, std::__1::__bit_const_reference<std::__1::vector<bool, std::__1::allocator<bool> > > >' requested here
        ::nlohmann::to_json(j, std::forward<ValueType>(val));
        ^
./json.hpp:1998:28: note: in instantiation of function template specialization 'nlohmann::adl_serializer<std::__1::__bit_const_reference<std::__1::vector<bool, std::__1::allocator<bool> > >,
      void>::to_json<nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer>,
      std::__1::__bit_const_reference<std::__1::vector<bool, std::__1::allocator<bool> > > >' requested here
        JSONSerializer<U>::to_json(*this, std::forward<CompatibleType>(val));
                           ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:1740:31: note: in instantiation of function template specialization 'nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>,
      bool, long long, unsigned long long, double, std::allocator, adl_serializer>::basic_json<std::__1::__bit_const_reference<std::__1::vector<bool, std::__1::allocator<bool> > >,
      std::__1::__bit_const_reference<std::__1::vector<bool, std::__1::allocator<bool> > >, 0>' requested here
            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
                              ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:1656:18: note: in instantiation of function template specialization 'std::__1::allocator<nlohmann::basic_json<std::map, std::vector,
      std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer> >::construct<nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long
      long, unsigned long long, double, std::allocator, adl_serializer>, std::__1::__bit_const_reference<std::__1::vector<bool, std::__1::allocator<bool> > > >' requested here
            {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
                 ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:1502:14: note: (skipping 8 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
            {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
             ^
./json.hpp:829:16: note: in instantiation of function template specialization 'nlohmann::detail::to_json<nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long
      long, double, std::allocator, adl_serializer>, std::__1::vector<bool, std::__1::allocator<bool> >, 0>' requested here
        return to_json(j, std::forward<T>(val));
               ^
./json.hpp:844:16: note: in instantiation of function template specialization 'nlohmann::detail::to_json_fn::call<nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long,
      unsigned long long, double, std::allocator, adl_serializer>, std::__1::vector<bool, std::__1::allocator<bool> > &>' requested here
        return call(j, std::forward<T>(val), priority_tag<1> {});
               ^
./json.hpp:934:9: note: in instantiation of function template specialization 'nlohmann::detail::to_json_fn::operator()<nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long,
      unsigned long long, double, std::allocator, adl_serializer>, std::__1::vector<bool, std::__1::allocator<bool> > &>' requested here
        ::nlohmann::to_json(j, std::forward<ValueType>(val));
        ^
./json.hpp:1998:28: note: in instantiation of function template specialization 'nlohmann::adl_serializer<std::__1::vector<bool, std::__1::allocator<bool> >, void>::to_json<nlohmann::basic_json<std::map,
      std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator, adl_serializer>, std::__1::vector<bool, std::__1::allocator<bool> > &>' requested here
        JSONSerializer<U>::to_json(*this, std::forward<CompatibleType>(val));
                           ^
main.cpp:8:21: note: in instantiation of function template specialization 'nlohmann::basic_json<std::map, std::vector, std::__1::basic_string<char>, bool, long long, unsigned long long, double, std::allocator,
      adl_serializer>::basic_json<std::__1::vector<bool, std::__1::allocator<bool> > &, std::__1::vector<bool, std::__1::allocator<bool> >, 0>' requested here
        j["bool_vector"] = boolVector;
                           ^
1 error generated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions