mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
rename get(table, key) to find()
This commit is contained in:
@@ -12,14 +12,14 @@
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_find_and_get)
|
BOOST_AUTO_TEST_CASE(test_find)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
toml::value v(true);
|
toml::value v(true);
|
||||||
bool thrown = false;
|
bool thrown = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
toml::get<toml::boolean>(v, "key");
|
toml::find<toml::boolean>(v, "key");
|
||||||
}
|
}
|
||||||
catch(toml::type_error const& te)
|
catch(toml::type_error const& te)
|
||||||
{
|
{
|
||||||
@@ -30,16 +30,16 @@ BOOST_AUTO_TEST_CASE(test_find_and_get)
|
|||||||
|
|
||||||
{
|
{
|
||||||
toml::table v{{"num", 42}};
|
toml::table v{{"num", 42}};
|
||||||
BOOST_CHECK_EQUAL(42, toml::get<int>(v, "num"));
|
BOOST_CHECK_EQUAL(42, toml::find<int>(v, "num"));
|
||||||
toml::get<toml::integer>(v, "num") = 54;
|
toml::find<toml::integer>(v, "num") = 54;
|
||||||
BOOST_CHECK_EQUAL(54, toml::get<int>(v, "num"));
|
BOOST_CHECK_EQUAL(54, toml::find<int>(v, "num"));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
toml::value v = toml::table{{"num", 42}};
|
toml::value v = toml::table{{"num", 42}};
|
||||||
BOOST_CHECK_EQUAL(42, toml::get<int>(v, "num"));
|
BOOST_CHECK_EQUAL(42, toml::find<int>(v, "num"));
|
||||||
toml::get<toml::integer>(v, "num") = 54;
|
toml::find<toml::integer>(v, "num") = 54;
|
||||||
BOOST_CHECK_EQUAL(54, toml::get<int>(v, "num"));
|
BOOST_CHECK_EQUAL(54, toml::find<int>(v, "num"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
toml/get.hpp
18
toml/get.hpp
@@ -270,8 +270,8 @@ T get(const toml::value& v)
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
decltype(::toml::get<T>(std::declval<const ::toml::value&>()))
|
decltype(::toml::get<T>(std::declval<const ::toml::value&>()))
|
||||||
get(const toml::table& tab, const toml::key& ky,
|
find(const toml::table& tab, const toml::key& ky,
|
||||||
std::string tablename = "unknown table")
|
std::string tablename = "unknown table")
|
||||||
{
|
{
|
||||||
if(tab.count(ky) == 0)
|
if(tab.count(ky) == 0)
|
||||||
{
|
{
|
||||||
@@ -282,8 +282,8 @@ get(const toml::table& tab, const toml::key& ky,
|
|||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
decltype(::toml::get<T>(std::declval<::toml::value&>()))
|
decltype(::toml::get<T>(std::declval<::toml::value&>()))
|
||||||
get(toml::table& tab, const toml::key& ky,
|
find(toml::table& tab, const toml::key& ky,
|
||||||
std::string tablename = "unknown table")
|
std::string tablename = "unknown table")
|
||||||
{
|
{
|
||||||
if(tab.count(ky) == 0)
|
if(tab.count(ky) == 0)
|
||||||
{
|
{
|
||||||
@@ -294,8 +294,8 @@ get(toml::table& tab, const toml::key& ky,
|
|||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
decltype(::toml::get<T>(std::declval<::toml::value&&>()))
|
decltype(::toml::get<T>(std::declval<::toml::value&&>()))
|
||||||
get(toml::table&& tab, const toml::key& ky,
|
find(toml::table&& tab, const toml::key& ky,
|
||||||
std::string tablename = "unknown table")
|
std::string tablename = "unknown table")
|
||||||
{
|
{
|
||||||
if(tab.count(ky) == 0)
|
if(tab.count(ky) == 0)
|
||||||
{
|
{
|
||||||
@@ -307,7 +307,7 @@ get(toml::table&& tab, const toml::key& ky,
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
decltype(::toml::get<T>(std::declval<const ::toml::value&>()))
|
decltype(::toml::get<T>(std::declval<const ::toml::value&>()))
|
||||||
get(const toml::value& v, const toml::key& ky)
|
find(const toml::value& v, const toml::key& ky)
|
||||||
{
|
{
|
||||||
const auto& tab = ::toml::get<toml::table>(v);
|
const auto& tab = ::toml::get<toml::table>(v);
|
||||||
if(tab.count(ky) == 0)
|
if(tab.count(ky) == 0)
|
||||||
@@ -320,7 +320,7 @@ get(const toml::value& v, const toml::key& ky)
|
|||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
decltype(::toml::get<T>(std::declval<::toml::value&>()))
|
decltype(::toml::get<T>(std::declval<::toml::value&>()))
|
||||||
get(toml::value& v, const toml::key& ky)
|
find(toml::value& v, const toml::key& ky)
|
||||||
{
|
{
|
||||||
auto& tab = ::toml::get<toml::table>(v);
|
auto& tab = ::toml::get<toml::table>(v);
|
||||||
if(tab.count(ky) == 0)
|
if(tab.count(ky) == 0)
|
||||||
@@ -333,7 +333,7 @@ get(toml::value& v, const toml::key& ky)
|
|||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
decltype(::toml::get<T>(std::declval<::toml::value&&>()))
|
decltype(::toml::get<T>(std::declval<::toml::value&&>()))
|
||||||
get(toml::value&& v, const toml::key& ky)
|
find(toml::value&& v, const toml::key& ky)
|
||||||
{
|
{
|
||||||
auto tab = ::toml::get<toml::table>(std::move(v));
|
auto tab = ::toml::get<toml::table>(std::move(v));
|
||||||
if(tab.count(ky) == 0)
|
if(tab.count(ky) == 0)
|
||||||
|
Reference in New Issue
Block a user