parse/value: add tribool support

This commit is contained in:
Danny Robson 2022-06-13 15:37:58 +10:00
parent 680e67eb77
commit 8b9ac3d599
2 changed files with 13 additions and 2 deletions

View File

@ -3,11 +3,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
* *
* Copyright 2017-2018 Danny Robson <danny@nerdcruft.net> * Copyright 2017-2018, 2022 Danny Robson <danny@nerdcruft.net>
*/ */
#include "value.hpp" #include "value.hpp"
#include "../bool.hpp"
#include "../cast.hpp" #include "../cast.hpp"
#include "preprocessor.hpp" #include "preprocessor.hpp"
@ -184,3 +185,12 @@ cruft::parse::value<bool> (cruft::view<char const*> &str)
throw std::invalid_argument ("invalid boolean string"); throw std::invalid_argument ("invalid boolean string");
} }
///////////////////////////////////////////////////////////////////////////////
template <>
cruft::tribool
cruft::parse::value<cruft::tribool> (cruft::view< char const*> &str)
{
return tribool (parse::value<bool> (str));
}

View File

@ -3,7 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
* *
* Copyright 2017-2018 Danny Robson <danny@nerdcruft.net> * Copyright 2017-2018, 2022 Danny Robson <danny@nerdcruft.net>
*/ */
#pragma once #pragma once
@ -11,6 +11,7 @@
#include "../view.hpp" #include "../view.hpp"
#include "enum.hpp" #include "enum.hpp"
namespace cruft::parse { namespace cruft::parse {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/// Extracts an instance of a native type T from the string [first, last). /// Extracts an instance of a native type T from the string [first, last).