1 // Copyright (c) 2020-2021 Antony Polukhin 2 // Copyright (c) 2020 Richard Hodges 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 7 // Test case from https://github.com/madmongo1/pfr_review/blob/master/pre-cxx20/test-2.cpp 8 9 #include <boost/pfr/functions_for.hpp> 10 11 #include <boost/utility/string_view.hpp> 12 13 #include <sstream> 14 #include <string> 15 16 #include <boost/core/lightweight_test.hpp> 17 18 namespace the_wild { 19 struct animal { 20 std::string name; 21 boost::string_view temperament; 22 }; 23 24 // Error: std::hash not specialized for type 25 // OR in C++14: 26 // Error: animal is not constexpr initializable 27 BOOST_PFR_FUNCTIONS_FOR(animal) 28 } // namespace the_wild 29 30 const auto fido = the_wild::animal { "fido", "aloof" }; 31 main()32int main() { 33 std::ostringstream oss; 34 oss << fido; 35 36 BOOST_TEST_EQ(oss.str(), "{\"fido\", \"aloof\"}"); 37 38 return boost::report_errors(); 39 } 40