From 6b16249a09d6a8263cc9679095020efce9affa33 Mon Sep 17 00:00:00 2001 From: Mohammad Nejati Date: Tue, 5 Dec 2023 15:39:57 +0000 Subject: [PATCH] Make operator / a friend of string_path Fixes #24 --- include/boost/property_tree/string_path.hpp | 37 ++++----------------- test/test_property_tree.hpp | 18 ++++++++-- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/include/boost/property_tree/string_path.hpp b/include/boost/property_tree/string_path.hpp index 6932d59b0..de2abc0a4 100644 --- a/include/boost/property_tree/string_path.hpp +++ b/include/boost/property_tree/string_path.hpp @@ -129,6 +129,13 @@ namespace boost { namespace property_tree return detail::dump_sequence(m_value); } + /// Concatenates two path components + friend string_path operator /(string_path p1, const string_path &p2) + { + p1 /= p2; + return p1; + } + /// Append a second path to this one. /// @pre o's separator is the same as this one's, or o has no separators string_path& operator /=(const string_path &o) { @@ -243,36 +250,6 @@ namespace boost { namespace property_tree typedef std::basic_string _string; typedef string_path< _string, id_translator<_string> > type; }; - - template inline - string_path operator /( - string_path p1, - const string_path &p2) - { - p1 /= p2; - return p1; - } - - // These shouldn't be necessary, but GCC won't find the one above. - template inline - string_path operator /( - string_path p1, - const typename String::value_type *p2) - { - p1 /= p2; - return p1; - } - - template inline - string_path operator /( - const typename String::value_type *p1, - const string_path &p2) - { - string_path t(p1); - t /= p2; - return t; - } - }} #endif diff --git a/test/test_property_tree.hpp b/test/test_property_tree.hpp index 4f2e59648..3fb4e1098 100644 --- a/test/test_property_tree.hpp +++ b/test/test_property_tree.hpp @@ -1026,16 +1026,30 @@ void test_path(PTREE *) } // Test operator / + { + path p = path(T("key1")) / path(T("key2.key3")); + BOOST_TEST(pt.get(p, 0) == 1); + } + { + path p = path(T("key1.key2")) / path(T("key3")); + BOOST_TEST(pt.get(p, 0) == 1); + } { path p = path(T("key1")) / T("key2.key3"); BOOST_TEST(pt.get(p, 0) == 1); } - - // Test operator / { path p = T("key1.key2") / path(T("key3")); BOOST_TEST(pt.get(p, 0) == 1); } + { + path p = path(T("key1")) / std::basic_string(T("key2.key3")); + BOOST_TEST(pt.get(p, 0) == 1); + } + { + path p = std::basic_string(T("key1.key2")) / path(T("key3")); + BOOST_TEST(pt.get(p, 0) == 1); + } }