kraken: utils: add 'StrongType'

I foresee the need to disambiguate a lot of `int`s.
This commit is contained in:
Bruno BELANYI 2022-03-12 01:10:03 +01:00
parent 382f374031
commit b7182826ab
3 changed files with 22 additions and 0 deletions

View file

@ -2,6 +2,7 @@ add_executable(kraken kraken.cc)
target_link_libraries(kraken PRIVATE common_options)
add_subdirectory(csv)
add_subdirectory(utils)
target_link_libraries(kraken PRIVATE
csv

3
src/utils/CMakeLists.txt Normal file
View file

@ -0,0 +1,3 @@
add_library(utils INTERFACE
strong-type.hh
)

18
src/utils/strong-type.hh Normal file
View file

@ -0,0 +1,18 @@
#pragma once
namespace kraken::utils {
/// A very simple strong type wrapper.
template <typename T, typename Tag>
struct StrongType {
explicit StrongType(T value) : value_(value) {}
explicit operator T() const {
return value_;
}
private:
T value_;
};
} // namespace kraken::utils