example_containers_set.cpp
Go to the documentation of this file.
1 // Licensed under the MIT License <http://opensource.org/licenses/MIT>.
2 // SPDX-License-Identifier: MIT
3 // Copyright (c) 2019 - 2024 Daniil Goncharov <neargye@gmail.com>.
4 // Copyright (c) 2022 - 2023 Bela Schaum <schaumb@gmail.com>.
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 
24 #if defined(_MSC_VER)
25 # pragma warning(push)
26 # pragma warning(disable : 4244) // warning C4244: 'argument': conversion from 'const T' to 'unsigned int', possible loss of data.
27 #endif
28 
29 #include <iostream>
30 
32 
33 enum class Color { RED = 1, GREEN = 2, BLUE = 4 };
34 template <>
36  static constexpr bool is_flags = true;
37 };
38 
39 int main() {
40 
41  std::cout << std::boolalpha;
43  std::cout << color_set.empty() << std::endl; // false
44  std::cout << color_set.size() << std::endl; // 3
45 
46  color_set.clear();
47  std::cout << color_set.empty() << std::endl; // true
48  std::cout << color_set.size() << std::endl; // 0
49 
50  color_set.insert(Color::GREEN);
51  color_set.insert(Color::BLUE);
52  std::cout << color_set.empty() << std::endl; // false
53  std::cout << color_set.size() << std::endl; // 2
54 
55  return 0;
56 }
Color::GREEN
@ GREEN
Catch::cout
std::ostream & cout()
magic_enum::containers::set
Definition: magic_enum_containers.hpp:841
magic_enum_containers.hpp
Color::RED
@ RED
magic_enum::customize::enum_range
Definition: magic_enum.hpp:172
Color
Color
Definition: example.cpp:28
Color::BLUE
@ BLUE
main
int main()
Definition: example_containers_set.cpp:39


magic_enum
Author(s):
autogenerated on Fri Feb 21 2025 03:20:18