Xped
Loading...
Searching...
No Matches
EnumStream.hpp
Go to the documentation of this file.
1#ifndef XPED_ENUM_STREAM_HPP_
2#define XPED_ENUM_STREAM_HPP_
3
4#include <boost/describe.hpp>
5
6namespace Xped {
7
8template <typename T, typename = typename std::enable_if_t<boost::describe::has_describe_enumerators<T>::value>>
9std::ostream& operator<<(std::ostream& os, const T& t)
10{
11 os << boost::describe::enum_to_string(t, "Unknown");
12 return os;
13}
14
15template <typename T, typename = typename std::enable_if_t<boost::describe::has_describe_enumerators<T>::value>>
16std::istream& operator>>(std::istream& is, T& t)
17{
18 std::string tmp;
19 is >> tmp;
20 bool success = boost::describe::enum_from_string(tmp.c_str(), t);
21 if(not success) { throw std::runtime_error(std::string("Invalid enumerator name '") + tmp + "'"); }
22 return is;
23}
24
25namespace Opts {
26
27template <typename T, typename = typename std::enable_if_t<boost::describe::has_describe_enumerators<T>::value>>
28std::ostream& operator<<(std::ostream& os, const T& t)
29{
30 os << boost::describe::enum_to_string(t, "Unknown");
31 return os;
32}
33
34template <typename T, typename = typename std::enable_if_t<boost::describe::has_describe_enumerators<T>::value>>
35std::istream& operator>>(std::istream& is, T& t)
36{
37 std::string tmp;
38 is >> tmp;
39 bool success = boost::describe::enum_from_string(tmp.c_str(), t);
40 if(not success) { throw std::runtime_error(std::string("Invalid enumerator name '") + tmp + "'"); }
41 return is;
42}
43
44} // namespace Opts
45} // namespace Xped
46#endif
std::ostream & operator<<(std::ostream &os, const T &t)
Definition: EnumStream.hpp:28
std::istream & operator>>(std::istream &is, T &t)
Definition: EnumStream.hpp:35
Definition: bench.cpp:62
std::ostream & operator<<(std::ostream &os, const FusionTree< depth, Symmetry > &tree)
Definition: FusionTree.hpp:93
std::istream & operator>>(std::istream &is, T &t)
Definition: EnumStream.hpp:16