diff --git a/include/cpptoml.h b/include/cpptoml.h index 7d843a0..a80f3d2 100644 --- a/include/cpptoml.h +++ b/include/cpptoml.h @@ -24,12 +24,23 @@ #include #include #include -#include +#include #include namespace cpptoml { + class base; // forward declaration +#if defined(CPPTOML_USE_MAP) + // a std::map will ensure that entries a sorted, albeit at a slight + // performance penalty relative to the (default) unordered_map + using mapStringToBase = std::map>; +#else + // by default an unordered_map is used for best performance as the + // toml specification does not require entries to be sorted + using mapStringToBase = std::unordered_map>; +#endif + template class option { @@ -394,15 +405,12 @@ class table : public base /** * tables can be iterated over. */ - using iterator - = std::unordered_map>::iterator; + using iterator = mapStringToBase::iterator; /** * tables can be iterated over. Const version. */ - using const_iterator - = std::unordered_map>::const_iterator; + using const_iterator = mapStringToBase::const_iterator; iterator begin() { @@ -679,7 +687,7 @@ class table : public base } } } - std::unordered_map> map_; + mapStringToBase map_; }; inline void table_array::print(std::ostream& stream, size_t depth,