Skip to content

Commit

Permalink
add CopyConst
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Nov 29, 2021
1 parent 6785ab5 commit 0b7611f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/llama/Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,4 +674,8 @@ namespace llama
});
return r;
}

/// Alias for ToT, adding `const` if FromT is const qualified.
template<typename FromT, typename ToT>
using CopyConst = std::conditional_t<std::is_const_v<FromT>, const ToT, ToT>;
} // namespace llama
8 changes: 8 additions & 0 deletions tests/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,11 @@ TEST_CASE("MergedRecordDims")
llama::Field<tag::Y, int>,
llama::Field<tag::Z, int>>>);
}

TEST_CASE("CopyConst")
{
STATIC_REQUIRE(std::is_same_v<llama::CopyConst<int, float>, float>);
STATIC_REQUIRE(std::is_same_v<llama::CopyConst<const int, float>, const float>);
STATIC_REQUIRE(std::is_same_v<llama::CopyConst<int, const float>, const float>);
STATIC_REQUIRE(std::is_same_v<llama::CopyConst<const int, const float>, const float>);
}

0 comments on commit 0b7611f

Please sign in to comment.