diff --git a/.travis.yml b/.travis.yml index b11ac99..8dc71fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,30 @@ dist: trusty matrix: include: + - os: linux + language: cpp + compiler: gcc + env: COMPILER="g++-4.8" CXX_STANDARD=11 + addons: + apt: + sources: + - sourceline: 'ppa:ubuntu-toolchain-r/test' + - sourceline: 'ppa:mhier/libboost-latest' + packages: + - g++-4.8 + - boost1.70 + - os: linux + language: cpp + compiler: gcc + env: COMPILER="g++-4.9" CXX_STANDARD=11 + addons: + apt: + sources: + - sourceline: 'ppa:ubuntu-toolchain-r/test' + - sourceline: 'ppa:mhier/libboost-latest' + packages: + - g++-4.9 + - boost1.70 - os: linux language: cpp compiler: gcc diff --git a/toml/comments.hpp b/toml/comments.hpp index 5d78440..9cf1ad4 100644 --- a/toml/comments.hpp +++ b/toml/comments.hpp @@ -81,6 +81,54 @@ struct preserve_comments void assign(std::initializer_list ini) {comments.assign(ini);} void assign(size_type n, const std::string& val) {comments.assign(n, val);} + // Related to the issue #97. + // + // It is known that `std::vector::insert` and `std::vector::erase` in + // the standard library implementation included in GCC 4.8.5 takes + // `std::vector::iterator` instead of `std::vector::const_iterator`. + // Because of the const-correctness, we cannot convert a `const_iterator` to + // an `iterator`. It causes compilation error in GCC 4.8.5. +#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) && !defined(__clang__) +# if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) <= 40805 +# define TOML11_WORKAROUND_GCC_4_8_X_STANDARD_LIBRARY_IMPLEMENTATION +# endif +#endif + +#ifdef TOML11_WORKAROUND_GCC_4_8_X_STANDARD_LIBRARY_IMPLEMENTATION + iterator insert(iterator p, const std::string& x) + { + return comments.insert(p, x); + } + iterator insert(iterator p, std::string&& x) + { + return comments.insert(p, std::move(x)); + } + void insert(iterator p, size_type n, const std::string& x) + { + return comments.insert(p, n, x); + } + template + void insert(iterator p, InputIterator first, InputIterator last) + { + return comments.insert(p, first, last); + } + void insert(iterator p, std::initializer_list ini) + { + return comments.insert(p, ini); + } + + template + iterator emplace(iterator p, Ts&& ... args) + { + return comments.emplace(p, std::forward(args)...); + } + + iterator erase(iterator pos) {return comments.erase(pos);} + iterator erase(iterator first, iterator last) + { + return comments.erase(first, last); + } +#else iterator insert(const_iterator p, const std::string& x) { return comments.insert(p, x); @@ -114,6 +162,7 @@ struct preserve_comments { return comments.erase(first, last); } +#endif void swap(preserve_comments& other) {comments.swap(other.comments);} diff --git a/toml/value.hpp b/toml/value.hpp index 63df1fc..1838524 100644 --- a/toml/value.hpp +++ b/toml/value.hpp @@ -20,11 +20,24 @@ namespace detail { // to show error messages. not recommended for users. -template class T, template class A> -region_base const& get_region(const basic_value&); -template class T, template class A> -void change_region(basic_value&, Region&&); +template +inline region_base const& get_region(const Value& v) +{ + return *(v.region_info_); +} + +template +void change_region(Value& v, Region&& reg) +{ + using region_type = typename std::remove_reference< + typename std::remove_cv::type + >::type; + + std::shared_ptr new_reg = + std::make_shared(std::forward(reg)); + v.region_info_ = new_reg; + return; +} template class T, template class A> @@ -1724,13 +1737,11 @@ class basic_value } // for error messages - template class T, template class A> - friend region_base const& detail::get_region(const basic_value&); + template + friend region_base const& detail::get_region(const Value& v); - template class T, template class A> - friend void detail::change_region(basic_value&, Region&&); + template + friend void detail::change_region(Value& v, Region&& reg); private: @@ -1760,30 +1771,6 @@ using value = basic_value; using array = typename value::array_type; using table = typename value::table_type; -namespace detail -{ -template class T, template class A> -inline region_base const& get_region(const basic_value& v) -{ - return *(v.region_info_); -} - -template class T, template class A> -void change_region(basic_value& v, Region&& reg) -{ - using region_type = typename std::remove_reference< - typename std::remove_cv::type - >::type; - - std::shared_ptr new_reg = - std::make_shared(std::forward(reg)); - v.region_info_ = new_reg; - return; -} -}// detail - template class T, template class A> inline bool operator==(const basic_value& lhs, const basic_value& rhs)