blob: 7db4be8cc6d1821776493084bb7a47098e2f69b2 [file] [log] [blame]
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +01001#pragma once
2
3#include <stdexcept>
4
5namespace utils
6{
7
8template <class T, T first, T last>
9inline T toEnum(int x)
10{
11 if (x < static_cast<decltype(x)>(first) ||
12 x > static_cast<decltype(x)>(last))
13 {
14 throw std::out_of_range("Value is not in range of enum");
15 }
16 return static_cast<T>(x);
17}
18} // namespace utils