aboutsummaryrefslogtreecommitdiff
path: root/libraries/toml11/include
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/toml11/include')
-rw-r--r--libraries/toml11/include/toml.hpp46
-rw-r--r--libraries/toml11/include/toml/color.hpp64
-rw-r--r--libraries/toml11/include/toml/combinator.hpp306
-rw-r--r--libraries/toml11/include/toml/comments.hpp466
-rw-r--r--libraries/toml11/include/toml/datetime.hpp631
-rw-r--r--libraries/toml11/include/toml/exception.hpp65
-rw-r--r--libraries/toml11/include/toml/from.hpp20
-rw-r--r--libraries/toml11/include/toml/get.hpp1068
-rw-r--r--libraries/toml11/include/toml/into.hpp20
-rw-r--r--libraries/toml11/include/toml/lexer.hpp270
-rw-r--r--libraries/toml11/include/toml/literal.hpp112
-rw-r--r--libraries/toml11/include/toml/macros.hpp121
-rw-r--r--libraries/toml11/include/toml/parser.hpp2177
-rw-r--r--libraries/toml11/include/toml/region.hpp417
-rw-r--r--libraries/toml11/include/toml/result.hpp717
-rw-r--r--libraries/toml11/include/toml/serializer.hpp853
-rw-r--r--libraries/toml11/include/toml/source_location.hpp233
-rw-r--r--libraries/toml11/include/toml/storage.hpp43
-rw-r--r--libraries/toml11/include/toml/string.hpp224
-rw-r--r--libraries/toml11/include/toml/traits.hpp300
-rw-r--r--libraries/toml11/include/toml/types.hpp150
-rw-r--r--libraries/toml11/include/toml/utility.hpp93
-rw-r--r--libraries/toml11/include/toml/value.hpp2023
23 files changed, 10419 insertions, 0 deletions
diff --git a/libraries/toml11/include/toml.hpp b/libraries/toml11/include/toml.hpp
new file mode 100644
index 00000000..9ed1216e
--- /dev/null
+++ b/libraries/toml11/include/toml.hpp
@@ -0,0 +1,46 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Toru Niina
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef TOML_FOR_MODERN_CPP
+#define TOML_FOR_MODERN_CPP
+
+#ifndef __cplusplus
+# error "__cplusplus is not defined"
+#endif
+
+#if __cplusplus < 201103L && _MSC_VER < 1900
+# error "toml11 requires C++11 or later."
+#endif
+
+#define TOML11_VERSION_MAJOR 3
+#define TOML11_VERSION_MINOR 6
+#define TOML11_VERSION_PATCH 1
+
+#include "toml/parser.hpp"
+#include "toml/literal.hpp"
+#include "toml/serializer.hpp"
+#include "toml/get.hpp"
+#include "toml/macros.hpp"
+
+#endif// TOML_FOR_MODERN_CPP
diff --git a/libraries/toml11/include/toml/color.hpp b/libraries/toml11/include/toml/color.hpp
new file mode 100644
index 00000000..4cb572cb
--- /dev/null
+++ b/libraries/toml11/include/toml/color.hpp
@@ -0,0 +1,64 @@
+#ifndef TOML11_COLOR_HPP
+#define TOML11_COLOR_HPP
+#include <cstdint>
+#include <ostream>
+
+#ifdef TOML11_COLORIZE_ERROR_MESSAGE
+#define TOML11_ERROR_MESSAGE_COLORIZED true
+#else
+#define TOML11_ERROR_MESSAGE_COLORIZED false
+#endif
+
+namespace toml
+{
+
+// put ANSI escape sequence to ostream
+namespace color_ansi
+{
+namespace detail
+{
+inline int colorize_index()
+{
+ static const int index = std::ios_base::xalloc();
+ return index;
+}
+} // detail
+
+inline std::ostream& colorize(std::ostream& os)
+{
+ // by default, it is zero.
+ os.iword(detail::colorize_index()) = 1;
+ return os;
+}
+inline std::ostream& nocolorize(std::ostream& os)
+{
+ os.iword(detail::colorize_index()) = 0;
+ return os;
+}
+inline std::ostream& reset (std::ostream& os)
+{if(os.iword(detail::colorize_index()) == 1) {os << "\033[00m";} return os;}
+inline std::ostream& bold (std::ostream& os)
+{if(os.iword(detail::colorize_index()) == 1) {os << "\033[01m";} return os;}
+inline std::ostream& grey (std::ostream& os)
+{if(os.iword(detail::colorize_index()) == 1) {os << "\033[30m";} return os;}
+inline std::ostream& red (std::ostream& os)
+{if(os.iword(detail::colorize_index()) == 1) {os << "\033[31m";} return os;}
+inline std::ostream& green (std::ostream& os)
+{if(os.iword(detail::colorize_index()) == 1) {os << "\033[32m";} return os;}
+inline std::ostream& yellow (std::ostream& os)
+{if(os.iword(detail::colorize_index()) == 1) {os << "\033[33m";} return os;}
+inline std::ostream& blue (std::ostream& os)
+{if(os.iword(detail::colorize_index()) == 1) {os << "\033[34m";} return os;}
+inline std::ostream& magenta(std::ostream& os)
+{if(os.iword(detail::colorize_index()) == 1) {os << "\033[35m";} return os;}
+inline std::ostream& cyan (std::ostream& os)
+{if(os.iword(detail::colorize_index()) == 1) {os << "\033[36m";} return os;}
+inline std::ostream& white (std::ostream& os)
+{if(os.iword(detail::colorize_index()) == 1) {os << "\033[37m";} return os;}
+} // color_ansi
+
+// ANSI escape sequence is the only and default colorization method currently
+namespace color = color_ansi;
+
+} // toml
+#endif// TOML11_COLOR_HPP
diff --git a/libraries/toml11/include/toml/combinator.hpp b/libraries/toml11/include/toml/combinator.hpp
new file mode 100644
index 00000000..e250188f
--- /dev/null
+++ b/libraries/toml11/include/toml/combinator.hpp
@@ -0,0 +1,306 @@
+// Copyright Toru Niina 2017.
+// Distributed under the MIT License.
+#ifndef TOML11_COMBINATOR_HPP
+#define TOML11_COMBINATOR_HPP
+#include <cassert>
+#include <cctype>
+#include <cstdio>
+
+#include <array>
+#include <iomanip>
+#include <iterator>
+#include <limits>
+#include <type_traits>
+
+#include "region.hpp"
+#include "result.hpp"
+#include "traits.hpp"
+#include "utility.hpp"
+
+// they scans characters and returns region if it matches to the condition.
+// when they fail, it does not change the location.
+// in lexer.hpp, these are used.
+
+namespace toml
+{
+namespace detail
+{
+
+// to output character as an error message.
+inline std::string show_char(const char c)
+{
+ // It supress an error that occurs only in Debug mode of MSVC++ on Windows.
+ // I'm not completely sure but they check the value of char to be in the
+ // range [0, 256) and some of the COMPLETELY VALID utf-8 character sometimes
+ // has negative value (if char has sign). So here it re-interprets c as
+ // unsigned char through pointer. In general, converting pointer to a
+ // pointer that has different type cause UB, but `(signed|unsigned)?char`
+ // are one of the exceptions. Converting pointer only to char and std::byte
+ // (c++17) are valid.
+ if(std::isgraph(*reinterpret_cast<unsigned char const*>(std::addressof(c))))
+ {
+ return std::string(1, c);
+ }
+ else
+ {
+ std::array<char, 5> buf;
+ buf.fill('\0');
+ const auto r = std::snprintf(
+ buf.data(), buf.size(), "0x%02x", static_cast<int>(c) & 0xFF);
+ (void) r; // Unused variable warning
+ assert(r == static_cast<int>(buf.size()) - 1);
+ return std::string(buf.data());
+ }
+}
+
+template<char C>
+struct character
+{
+ static constexpr char target = C;
+
+ static result<region, none_t>
+ invoke(location& loc)
+ {
+ if(loc.iter() == loc.end()) {return none();}
+ const auto first = loc.iter();
+
+ const char c = *(loc.iter());
+ if(c != target)
+ {
+ return none();
+ }
+ loc.advance(); // update location
+
+ return ok(region(loc, first, loc.iter()));
+ }
+};
+template<char C>
+constexpr char character<C>::target;
+
+// closed interval [Low, Up]. both Low and Up are included.
+template<char Low, char Up>
+struct in_range
+{
+ // assuming ascii part of UTF-8...
+ static_assert(Low <= Up, "lower bound should be less than upper bound.");
+
+ static constexpr char upper = Up;
+ static constexpr char lower = Low;
+
+ static result<region, none_t>
+ invoke(location& loc)
+ {
+ if(loc.iter() == loc.end()) {return none();}
+ const auto first = loc.iter();
+
+ const char c = *(loc.iter());
+ if(c < lower || upper < c)
+ {
+ return none();
+ }
+
+ loc.advance();
+ return ok(region(loc, first, loc.iter()));
+ }
+};
+template<char L, char U> constexpr char in_range<L, U>::upper;
+template<char L, char U> constexpr char in_range<L, U>::lower;
+
+// keep iterator if `Combinator` matches. otherwise, increment `iter` by 1 char.
+// for detecting invalid characters, like control sequences in toml string.
+template<typename Combinator>
+struct exclude
+{
+ static result<region, none_t>
+ invoke(location& loc)
+ {
+ if(loc.iter() == loc.end()) {return none();}
+ auto first = loc.iter();
+
+ auto rslt = Combinator::invoke(loc);
+ if(rslt.is_ok())
+ {
+ loc.reset(first);
+ return none();
+ }
+ loc.reset(std::next(first)); // XXX maybe loc.advance() is okay but...
+ return ok(region(loc, first, loc.iter()));
+ }
+};
+
+// increment `iter`, if matches. otherwise, just return empty string.
+template<typename Combinator>
+struct maybe
+{
+ static result<region, none_t>
+ invoke(location& loc)
+ {
+ const auto rslt = Combinator::invoke(loc);
+ if(rslt.is_ok())
+ {
+ return rslt;
+ }
+ return ok(region(loc));
+ }
+};
+
+template<typename ... Ts>
+struct sequence;
+
+template<typename Head, typename ... Tail>
+struct sequence<Head, Tail...>
+{
+ static result<region, none_t>
+ invoke(location& loc)
+ {
+ const auto first = loc.iter();
+ const auto rslt = Head::invoke(loc);
+ if(rslt.is_err())
+ {
+ loc.reset(first);
+ return none();
+ }
+ return sequence<Tail...>::invoke(loc, std::move(rslt.unwrap()), first);
+ }
+
+ // called from the above function only, recursively.
+ template<typename Iterator>
+ static result<region, none_t>
+ invoke(location& loc, region reg, Iterator first)
+ {
+ const auto rslt = Head::invoke(loc);
+ if(rslt.is_err())
+ {
+ loc.reset(first);
+ return none();
+ }
+ reg += rslt.unwrap(); // concat regions
+ return sequence<Tail...>::invoke(loc, std::move(reg), first);
+ }
+};
+
+template<typename Head>
+struct sequence<Head>
+{
+ // would be called from sequence<T ...>::invoke only.
+ template<typename Iterator>
+ static result<region, none_t>
+ invoke(location& loc, region reg, Iterator first)
+ {
+ const auto rslt = Head::invoke(loc);
+ if(rslt.is_err())
+ {
+ loc.reset(first);
+ return none();
+ }
+ reg += rslt.unwrap(); // concat regions
+ return ok(reg);
+ }
+};
+
+template<typename ... Ts>
+struct either;
+
+template<typename Head, typename ... Tail>
+struct either<Head, Tail...>
+{
+ static result<region, none_t>
+ invoke(location& loc)
+ {
+ const auto rslt = Head::invoke(loc);
+ if(rslt.is_ok()) {return rslt;}
+ return either<Tail...>::invoke(loc);
+ }
+};
+template<typename Head>
+struct either<Head>
+{
+ static result<region, none_t>
+ invoke(location& loc)
+ {
+ return Head::invoke(loc);
+ }
+};
+
+template<typename T, typename N>
+struct repeat;
+
+template<std::size_t N> struct exactly{};
+template<std::size_t N> struct at_least{};
+struct unlimited{};
+
+template<typename T, std::size_t N>
+struct repeat<T, exactly<N>>
+{
+ static result<region, none_t>
+ invoke(location& loc)
+ {
+ region retval(loc);
+ const auto first = loc.iter();
+ for(std::size_t i=0; i<N; ++i)
+ {
+ auto rslt = T::invoke(loc);
+ if(rslt.is_err())
+ {
+ loc.reset(first);
+ return none();
+ }
+ retval += rslt.unwrap();
+ }
+ return ok(std::move(retval));
+ }
+};
+
+template<typename T, std::size_t N>
+struct repeat<T, at_least<N>>
+{
+ static result<region, none_t>
+ invoke(location& loc)
+ {
+ region retval(loc);
+
+ const auto first = loc.iter();
+ for(std::size_t i=0; i<N; ++i)
+ {
+ auto rslt = T::invoke(loc);
+ if(rslt.is_err())
+ {
+ loc.reset(first);
+ return none();
+ }
+ retval += rslt.unwrap();
+ }
+ while(true)
+ {
+ auto rslt = T::invoke(loc);
+ if(rslt.is_err())
+ {
+ return ok(std::move(retval));
+ }
+ retval += rslt.unwrap();
+ }
+ }
+};
+
+template<typename T>
+struct repeat<T, unlimited>
+{
+ static result<region, none_t>
+ invoke(location& loc)
+ {
+ region retval(loc);
+ while(true)
+ {
+ auto rslt = T::invoke(loc);
+ if(rslt.is_err())
+ {
+ return ok(std::move(retval));
+ }
+ retval += rslt.unwrap();
+ }
+ }
+};
+
+} // detail
+} // toml
+#endif// TOML11_COMBINATOR_HPP
diff --git a/libraries/toml11/include/toml/comments.hpp b/libraries/toml11/include/toml/comments.hpp
new file mode 100644
index 00000000..92fc8e13
--- /dev/null
+++ b/libraries/toml11/include/toml/comments.hpp
@@ -0,0 +1,466 @@
+// Copyright Toru Niina 2019.
+// Distributed under the MIT License.
+#ifndef TOML11_COMMENTS_HPP
+#define TOML11_COMMENTS_HPP
+#include <initializer_list>
+#include <iterator>
+#include <stdexcept>
+#include <string>
+#include <type_traits>
+#include <utility>
+#include <vector>
+
+// This file provides mainly two classes, `preserve_comments` and `discard_comments`.
+// Those two are a container that have the same interface as `std::vector<std::string>`
+// but bahaves in the opposite way. `preserve_comments` is just the same as
+// `std::vector<std::string>` and each `std::string` corresponds to a comment line.
+// Conversely, `discard_comments` discards all the strings and ignores everything
+// assigned in it. `discard_comments` is always empty and you will encounter an
+// error whenever you access to the element.
+namespace toml
+{
+struct discard_comments; // forward decl
+
+// use it in the following way
+//
+// const toml::basic_value<toml::preserve_comments> data =
+// toml::parse<toml::preserve_comments>("example.toml");
+//
+// the interface is almost the same as std::vector<std::string>.
+struct preserve_comments
+{
+ // `container_type` is not provided in discard_comments.
+ // do not use this inner-type in a generic code.
+ using container_type = std::vector<std::string>;
+
+ using size_type = container_type::size_type;
+ using difference_type = container_type::difference_type;
+ using value_type = container_type::value_type;
+ using reference = container_type::reference;
+ using const_reference = container_type::const_reference;
+ using pointer = container_type::pointer;
+ using const_pointer = container_type::const_pointer;
+ using iterator = container_type::iterator;
+ using const_iterator = container_type::const_iterator;
+ using reverse_iterator = container_type::reverse_iterator;
+ using const_reverse_iterator = container_type::const_reverse_iterator;
+
+ preserve_comments() = default;
+ ~preserve_comments() = default;
+ preserve_comments(preserve_comments const&) = default;
+ preserve_comments(preserve_comments &&) = default;
+ preserve_comments& operator=(preserve_comments const&) = default;
+ preserve_comments& operator=(preserve_comments &&) = default;
+
+ explicit preserve_comments(const std::vector<std::string>& c): comments(c){}
+ explicit preserve_comments(std::vector<std::string>&& c)
+ : comments(std::move(c))
+ {}
+ preserve_comments& operator=(const std::vector<std::string>& c)
+ {
+ comments = c;
+ return *this;
+ }
+ preserve_comments& operator=(std::vector<std::string>&& c)
+ {
+ comments = std::move(c);
+ return *this;
+ }
+
+ explicit preserve_comments(const discard_comments&) {}
+
+ explicit preserve_comments(size_type n): comments(n) {}
+ preserve_comments(size_type n, const std::string& x): comments(n, x) {}
+ preserve_comments(std::initializer_list<std::string> x): comments(x) {}
+ template<typename InputIterator>
+ preserve_comments(InputIterator first, InputIterator last)
+ : comments(first, last)
+ {}
+
+ template<typename InputIterator>
+ void assign(InputIterator first, InputIterator last) {comments.assign(first, last);}
+ void assign(std::initializer_list<std::string> 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<typename InputIterator>
+ void insert(iterator p, InputIterator first, InputIterator last)
+ {
+ return comments.insert(p, first, last);
+ }
+ void insert(iterator p, std::initializer_list<std::string> ini)
+ {
+ return comments.insert(p, ini);
+ }
+
+ template<typename ... Ts>
+ iterator emplace(iterator p, Ts&& ... args)
+ {
+ return comments.emplace(p, std::forward<Ts>(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);
+ }
+ iterator insert(const_iterator p, std::string&& x)
+ {
+ return comments.insert(p, std::move(x));
+ }
+ iterator insert(const_iterator p, size_type n, const std::string& x)
+ {
+ return comments.insert(p, n, x);
+ }
+ template<typename InputIterator>
+ iterator insert(const_iterator p, InputIterator first, InputIterator last)
+ {
+ return comments.insert(p, first, last);
+ }
+ iterator insert(const_iterator p, std::initializer_list<std::string> ini)
+ {
+ return comments.insert(p, ini);
+ }
+
+ template<typename ... Ts>
+ iterator emplace(const_iterator p, Ts&& ... args)
+ {
+ return comments.emplace(p, std::forward<Ts>(args)...);
+ }
+
+ iterator erase(const_iterator pos) {return comments.erase(pos);}
+ iterator erase(const_iterator first, const_iterator last)
+ {
+ return comments.erase(first, last);
+ }
+#endif
+
+ void swap(preserve_comments& other) {comments.swap(other.comments);}
+
+ void push_back(const std::string& v) {comments.push_back(v);}
+ void push_back(std::string&& v) {comments.push_back(std::move(v));}
+ void pop_back() {comments.pop_back();}
+
+ template<typename ... Ts>
+ void emplace_back(Ts&& ... args) {comments.emplace_back(std::forward<Ts>(args)...);}
+
+ void clear() {comments.clear();}
+
+ size_type size() const noexcept {return comments.size();}
+ size_type max_size() const noexcept {return comments.max_size();}
+ size_type capacity() const noexcept {return comments.capacity();}
+ bool empty() const noexcept {return comments.empty();}
+
+ void reserve(size_type n) {comments.reserve(n);}
+ void resize(size_type n) {comments.resize(n);}
+ void resize(size_type n, const std::string& c) {comments.resize(n, c);}
+ void shrink_to_fit() {comments.shrink_to_fit();}
+
+ reference operator[](const size_type n) noexcept {return comments[n];}
+ const_reference operator[](const size_type n) const noexcept {return comments[n];}
+ reference at(const size_type n) {return comments.at(n);}
+ const_reference at(const size_type n) const {return comments.at(n);}
+ reference front() noexcept {return comments.front();}
+ const_reference front() const noexcept {return comments.front();}
+ reference back() noexcept {return comments.back();}
+ const_reference back() const noexcept {return comments.back();}
+
+ pointer data() noexcept {return comments.data();}
+ const_pointer data() const noexcept {return comments.data();}
+
+ iterator begin() noexcept {return comments.begin();}
+ iterator end() noexcept {return comments.end();}
+ const_iterator begin() const noexcept {return comments.begin();}
+ const_iterator end() const noexcept {return comments.end();}
+ const_iterator cbegin() const noexcept {return comments.cbegin();}
+ const_iterator cend() const noexcept {return comments.cend();}
+
+ reverse_iterator rbegin() noexcept {return comments.rbegin();}
+ reverse_iterator rend() noexcept {return comments.rend();}
+ const_reverse_iterator rbegin() const noexcept {return comments.rbegin();}
+ const_reverse_iterator rend() const noexcept {return comments.rend();}
+ const_reverse_iterator crbegin() const noexcept {return comments.crbegin();}
+ const_reverse_iterator crend() const noexcept {return comments.crend();}
+
+ friend bool operator==(const preserve_comments&, const preserve_comments&);
+ friend bool operator!=(const preserve_comments&, const preserve_comments&);
+ friend bool operator< (const preserve_comments&, const preserve_comments&);
+ friend bool operator<=(const preserve_comments&, const preserve_comments&);
+ friend bool operator> (const preserve_comments&, const preserve_comments&);
+ friend bool operator>=(const preserve_comments&, const preserve_comments&);
+
+ friend void swap(preserve_comments&, std::vector<std::string>&);
+ friend void swap(std::vector<std::string>&, preserve_comments&);
+
+ private:
+
+ container_type comments;
+};
+
+inline bool operator==(const preserve_comments& lhs, const preserve_comments& rhs) {return lhs.comments == rhs.comments;}
+inline bool operator!=(const preserve_comments& lhs, const preserve_comments& rhs) {return lhs.comments != rhs.comments;}
+inline bool operator< (const preserve_comments& lhs, const preserve_comments& rhs) {return lhs.comments < rhs.comments;}
+inline bool operator<=(const preserve_comments& lhs, const preserve_comments& rhs) {return lhs.comments <= rhs.comments;}
+inline bool operator> (const preserve_comments& lhs, const preserve_comments& rhs) {return lhs.comments > rhs.comments;}
+inline bool operator>=(const preserve_comments& lhs, const preserve_comments& rhs) {return lhs.comments >= rhs.comments;}
+
+inline void swap(preserve_comments& lhs, preserve_comments& rhs)
+{
+ lhs.swap(rhs);
+ return;
+}
+inline void swap(preserve_comments& lhs, std::vector<std::string>& rhs)
+{
+ lhs.comments.swap(rhs);
+ return;
+}
+inline void swap(std::vector<std::string>& lhs, preserve_comments& rhs)
+{
+ lhs.swap(rhs.comments);
+ return;
+}
+
+template<typename charT, typename traits>
+std::basic_ostream<charT, traits>&
+operator<<(std::basic_ostream<charT, traits>& os, const preserve_comments& com)
+{
+ for(const auto& c : com)
+ {
+ os << '#' << c << '\n';
+ }
+ return os;
+}
+
+namespace detail
+{
+
+// To provide the same interface with `preserve_comments`, `discard_comments`
+// should have an iterator. But it does not contain anything, so we need to
+// add an iterator that points nothing.
+//
+// It always points null, so DO NOT unwrap this iterator. It always crashes
+// your program.
+template<typename T, bool is_const>
+struct empty_iterator
+{
+ using value_type = T;
+ using reference_type = typename std::conditional<is_const, T const&, T&>::type;
+ using pointer_type = typename std::conditional<is_const, T const*, T*>::type;
+ using difference_type = std::ptrdiff_t;
+ using iterator_category = std::random_access_iterator_tag;
+
+ empty_iterator() = default;
+ ~empty_iterator() = default;
+ empty_iterator(empty_iterator const&) = default;
+ empty_iterator(empty_iterator &&) = default;
+ empty_iterator& operator=(empty_iterator const&) = default;
+ empty_iterator& operator=(empty_iterator &&) = default;
+
+ // DO NOT call these operators.
+ reference_type operator*() const noexcept {std::terminate();}
+ pointer_type operator->() const noexcept {return nullptr;}
+ reference_type operator[](difference_type) const noexcept {return this->operator*();}
+
+ // These operators do nothing.
+ empty_iterator& operator++() noexcept {return *this;}
+ empty_iterator operator++(int) noexcept {return *this;}
+ empty_iterator& operator--() noexcept {return *this;}
+ empty_iterator operator--(int) noexcept {return *this;}
+
+ empty_iterator& operator+=(difference_type) noexcept {return *this;}
+ empty_iterator& operator-=(difference_type) noexcept {return *this;}
+
+ empty_iterator operator+(difference_type) const noexcept {return *this;}
+ empty_iterator operator-(difference_type) const noexcept {return *this;}
+};
+
+template<typename T, bool C>
+bool operator==(const empty_iterator<T, C>&, const empty_iterator<T, C>&) noexcept {return true;}
+template<typename T, bool C>
+bool operator!=(const empty_iterator<T, C>&, const empty_iterator<T, C>&) noexcept {return false;}
+template<typename T, bool C>
+bool operator< (const empty_iterator<T, C>&, const empty_iterator<T, C>&) noexcept {return false;}
+template<typename T, bool C>
+bool operator<=(const empty_iterator<T, C>&, const empty_iterator<T, C>&) noexcept {return true;}
+template<typename T, bool C>
+bool operator> (const empty_iterator<T, C>&, const empty_iterator<T, C>&) noexcept {return false;}
+template<typename T, bool C>
+bool operator>=(const empty_iterator<T, C>&, const empty_iterator<T, C>&) noexcept {return true;}
+
+template<typename T, bool C>
+typename empty_iterator<T, C>::difference_type
+operator-(const empty_iterator<T, C>&, const empty_iterator<T, C>&) noexcept {return 0;}
+
+template<typename T, bool C>
+empty_iterator<T, C>
+operator+(typename empty_iterator<T, C>::difference_type, const empty_iterator<T, C>& rhs) noexcept {return rhs;}
+template<typename T, bool C>
+empty_iterator<T, C>
+operator+(const empty_iterator<T, C>& lhs, typename empty_iterator<T, C>::difference_type) noexcept {return lhs;}
+
+} // detail
+
+// The default comment type. It discards all the comments. It requires only one
+// byte to contain, so the memory footprint is smaller than preserve_comments.
+//
+// It just ignores `push_back`, `insert`, `erase`, and any other modifications.
+// IT always returns size() == 0, the iterator taken by `begin()` is always the
+// same as that of `end()`, and accessing through `operator[]` or iterators
+// always causes a segmentation fault. DO NOT access to the element of this.
+//
+// Why this is chose as the default type is because the last version (2.x.y)
+// does not contain any comments in a value. To minimize the impact on the
+// efficiency, this is choosed as a default.
+//
+// To reduce the memory footprint, later we can try empty base optimization (EBO).
+struct discard_comments
+{
+ using size_type = std::size_t;
+ using difference_type = std::ptrdiff_t;
+ using value_type = std::string;
+ using reference = std::string&;
+ using const_reference = std::string const&;
+ using pointer = std::string*;
+ using const_pointer = std::string const*;
+ using iterator = detail::empty_iterator<std::string, false>;
+ using const_iterator = detail::empty_iterator<std::string, true>;
+ using reverse_iterator = detail::empty_iterator<std::string, false>;
+ using const_reverse_iterator = detail::empty_iterator<std::string, true>;
+
+ discard_comments() = default;
+ ~discard_comments() = default;
+ discard_comments(discard_comments const&) = default;
+ discard_comments(discard_comments &&) = default;
+ discard_comments& operator=(discard_comments const&) = default;
+ discard_comments& operator=(discard_comments &&) = default;
+
+ explicit discard_comments(const std::vector<std::string>&) noexcept {}
+ explicit discard_comments(std::vector<std::string>&&) noexcept {}
+ discard_comments& operator=(const std::vector<std::string>&) noexcept {return *this;}
+ discard_comments& operator=(std::vector<std::string>&&) noexcept {return *this;}
+
+ explicit discard_comments(const preserve_comments&) noexcept {}
+
+ explicit discard_comments(size_type) noexcept {}
+ discard_comments(size_type, const std::string&) noexcept {}
+ discard_comments(std::initializer_list<std::string>) noexcept {}
+ template<typename InputIterator>
+ discard_comments(InputIterator, InputIterator) noexcept {}
+
+ template<typename InputIterator>
+ void assign(InputIterator, InputIterator) noexcept {}
+ void assign(std::initializer_list<std::string>) noexcept {}
+ void assign(size_type, const std::string&) noexcept {}
+
+ iterator insert(const_iterator, const std::string&) {return iterator{};}
+ iterator insert(const_iterator, std::string&&) {return iterator{};}
+ iterator insert(const_iterator, size_type, const std::string&)