update README

This commit is contained in:
2019-11-22 06:34:53 +07:00
parent 3b47ce65e4
commit 516759f961
2 changed files with 24 additions and 22 deletions

View File

@@ -164,33 +164,35 @@ namespace
(white = red | green | blue)) (white = red | green | blue))
} }
SECTION("traits_using") { int main() {
// size // size
STATIC_REQUIRE(color_traits::size == 4); static_assert(color_traits::size == 4);
// to_underlying // to_underlying
STATIC_REQUIRE(color_traits::to_underlying(color::white) == 0xFFFFFF); static_assert(color_traits::to_underlying(color::white) == 0xFFFFFF);
// to_string // to_string
STATIC_REQUIRE(color_traits::to_string(color::red) == "red"); static_assert(color_traits::to_string(color::red) == "red");
STATIC_REQUIRE(color_traits::to_string(color(42)) == std::nullopt); static_assert(color_traits::to_string(color(42)) == std::nullopt);
// from_string // from_string
STATIC_REQUIRE(color_traits::from_string("green") == color::green); static_assert(color_traits::from_string("green") == color::green);
STATIC_REQUIRE(color_traits::from_string("error") == std::nullopt); static_assert(color_traits::from_string("error") == std::nullopt);
// to_index // to_index
STATIC_REQUIRE(color_traits::to_index(color::blue) == 2); static_assert(color_traits::to_index(color::blue) == 2);
STATIC_REQUIRE(color_traits::to_index(color(42)) == std::nullopt); static_assert(color_traits::to_index(color(42)) == std::nullopt);
// from_index // from_index
STATIC_REQUIRE(color_traits::from_index(2) == color::blue); static_assert(color_traits::from_index(2) == color::blue);
STATIC_REQUIRE(color_traits::from_index(42) == std::nullopt); static_assert(color_traits::from_index(42) == std::nullopt);
// names // names
for ( auto n : color_traits::names ) { for ( auto n : color_traits::names ) {
std::cout << n << ","; std::cout << n << ",";
} // stdout: red,green,blue, } // stdout: red,green,blue,
return 0;
} }
``` ```

View File

@@ -24,30 +24,30 @@ namespace
TEST_CASE("examples") { TEST_CASE("examples") {
SECTION("traits_using") { SECTION("traits_using") {
// size // size
STATIC_REQUIRE(color_traits::size == 4); static_assert(color_traits::size == 4);
// to_underlying // to_underlying
STATIC_REQUIRE(color_traits::to_underlying(color::white) == 0xFFFFFF); static_assert(color_traits::to_underlying(color::white) == 0xFFFFFF);
// to_string // to_string
STATIC_REQUIRE(color_traits::to_string(color::red) == "red"); static_assert(color_traits::to_string(color::red) == "red");
STATIC_REQUIRE(color_traits::to_string(color(42)) == std::nullopt); static_assert(color_traits::to_string(color(42)) == std::nullopt);
// from_string // from_string
STATIC_REQUIRE(color_traits::from_string("green") == color::green); static_assert(color_traits::from_string("green") == color::green);
STATIC_REQUIRE(color_traits::from_string("error") == std::nullopt); static_assert(color_traits::from_string("error") == std::nullopt);
// to_index // to_index
STATIC_REQUIRE(color_traits::to_index(color::blue) == 2u); static_assert(color_traits::to_index(color::blue) == 2u);
STATIC_REQUIRE(color_traits::to_index(color(42)) == std::nullopt); static_assert(color_traits::to_index(color(42)) == std::nullopt);
// from_index // from_index
STATIC_REQUIRE(color_traits::from_index(2) == color::blue); static_assert(color_traits::from_index(2) == color::blue);
STATIC_REQUIRE(color_traits::from_index(42) == std::nullopt); static_assert(color_traits::from_index(42) == std::nullopt);
// names // names
for ( auto n : color_traits::names ) { for ( auto n : color_traits::names ) {
std::cout << n << ","; std::cout << n << ",";
} } // stdout: red,green,blue,
} }
} }