diff --git a/include/llama/Core.hpp b/include/llama/Core.hpp index 50c264e2ee..72b3e3cebd 100644 --- a/include/llama/Core.hpp +++ b/include/llama/Core.hpp @@ -52,6 +52,12 @@ namespace llama { }; + /// @brief Tells whether the given type is allowed as a field type in LLAMA. Such types need to be trivially + /// constructible and trivially destructible. + template + inline constexpr bool isAllowedFieldType + = std::is_trivially_constructible_v&& std::is_trivially_destructible_v; + /// Record dimension tree node which may either be a leaf or refer to a child tree presented as another \ref /// Record. /// \tparam Tag Name of the node. May be any type (struct, class). @@ -62,6 +68,7 @@ namespace llama template struct Field { + static_assert(isAllowedFieldType, "This field's type is not allowed"); }; struct NrAndOffset diff --git a/tests/recorddimension.cpp b/tests/recorddimension.cpp index 8fd780ab11..e21f7a8497 100644 --- a/tests/recorddimension.cpp +++ b/tests/recorddimension.cpp @@ -35,14 +35,14 @@ TEST_CASE("recorddim.record_with_int[3]") int& e2 = view(0u)(Tag{})(2_RC); } -TEST_CASE("recorddim.record_with_std::complex") -{ - using RecordDim = llama::Record>>; - auto view = allocView(llama::mapping::AoS{llama::ArrayDims{1}, RecordDim{}}); - - std::complex& e = view(0u)(Tag{}); - e = {2, 3}; -} +// TEST_CASE("recorddim.record_with_std::complex") +//{ +// using RecordDim = llama::Record>>; +// auto view = allocView(llama::mapping::AoS{llama::ArrayDims{1}, RecordDim{}}); +// +// std::complex& e = view(0u)(Tag{}); +// e = {2, 3}; +//} TEST_CASE("recorddim.record_with_std::array") { @@ -53,23 +53,23 @@ TEST_CASE("recorddim.record_with_std::array") e = {2, 3, 4, 5}; } -TEST_CASE("recorddim.record_with_std::vector") -{ - using RecordDim = llama::Record>>; - auto view = allocView(llama::mapping::AoS{llama::ArrayDims{1}, RecordDim{}}); - - std::vector& e = view(0u)(Tag{}); - // e = {2, 3, 4, 5}; // FIXME: LLAMA memory is uninitialized -} - -TEST_CASE("recorddim.record_with_std::atomic") -{ - using RecordDim = llama::Record>>; - auto view = allocView(llama::mapping::AoS{llama::ArrayDims{1}, RecordDim{}}); - - std::atomic& e = view(0u)(Tag{}); - // e++; // FIXME: LLAMA memory is uninitialized -} +// TEST_CASE("recorddim.record_with_std::vector") +//{ +// using RecordDim = llama::Record>>; +// auto view = allocView(llama::mapping::AoS{llama::ArrayDims{1}, RecordDim{}}); +// +// std::vector& e = view(0u)(Tag{}); +// // e = {2, 3, 4, 5}; // FIXME: LLAMA memory is uninitialized +//} + +// TEST_CASE("recorddim.record_with_std::atomic") +//{ +// using RecordDim = llama::Record>>; +// auto view = allocView(llama::mapping::AoS{llama::ArrayDims{1}, RecordDim{}}); +// +// std::atomic& e = view(0u)(Tag{}); +// // e++; // FIXME: LLAMA memory is uninitialized +//} TEST_CASE("recorddim.record_with_noncopyable") { @@ -113,62 +113,62 @@ TEST_CASE("recorddim.record_with_nonmoveable") e.value = 0; } -TEST_CASE("recorddim.record_with_nondefaultconstructible") -{ - struct Element - { - Element() = delete; - int value; - }; - - using RecordDim = llama::Record>; - auto view = allocView(llama::mapping::AoS{llama::ArrayDims{1}, RecordDim{}}); - - Element& e = view(0u)(Tag{}); - e.value = 0; -} - -TEST_CASE("recorddim.record_with_nontrivial_ctor") -{ - struct Element - { - int value = 42; - }; - - using RecordDim = llama::Record>; - auto view = allocView(llama::mapping::AoS{llama::ArrayDims{1}, RecordDim{}}); - - Element& e = view(0u)(Tag{}); - // CHECK(e.value == 42); // FIXME: LLAMA memory is uninitialized -} - -namespace -{ - struct UniqueInt - { - int value = counter++; - - explicit operator int() const - { - return value; - } - - private: - inline static int counter = 0; - }; -} // namespace - -TEST_CASE("recorddim.record_with_nontrivial_ctor2") -{ - using RecordDim = llama::Record>; - auto view = allocView(llama::mapping::AoS{llama::ArrayDims{1}, RecordDim{}}); - - // FIXME: LLAMA memory is uninitialized - // CHECK(view(ArrayDims{0})(Tag{}) == 0); - // CHECK(view(ArrayDims{1})(Tag{}) == 1); - // CHECK(view(ArrayDims{2})(Tag{}) == 2); - // CHECK(view(ArrayDims{15})(Tag{}) == 15); -} +// TEST_CASE("recorddim.record_with_nondefaultconstructible") +//{ +// struct Element +// { +// Element() = delete; +// int value; +// }; +// +// using RecordDim = llama::Record>; +// auto view = allocView(llama::mapping::AoS{llama::ArrayDims{1}, RecordDim{}}); +// +// Element& e = view(0u)(Tag{}); +// e.value = 0; +//} + +// TEST_CASE("recorddim.record_with_nontrivial_ctor") +//{ +// struct Element +// { +// int value = 42; +// }; +// +// using RecordDim = llama::Record>; +// auto view = allocView(llama::mapping::AoS{llama::ArrayDims{1}, RecordDim{}}); +// +// Element& e = view(0u)(Tag{}); +// // CHECK(e.value == 42); // FIXME: LLAMA memory is uninitialized +//} + +// namespace +//{ +// struct UniqueInt +// { +// int value = counter++; +// +// explicit operator int() const +// { +// return value; +// } +// +// private: +// inline static int counter = 0; +// }; +//} // namespace +// +// TEST_CASE("recorddim.record_with_nontrivial_ctor2") +//{ +// using RecordDim = llama::Record>; +// auto view = allocView(llama::mapping::AoS{llama::ArrayDims{1}, RecordDim{}}); +// +// // FIXME: LLAMA memory is uninitialized +// // CHECK(view(ArrayDims{0})(Tag{}) == 0); +// // CHECK(view(ArrayDims{1})(Tag{}) == 1); +// // CHECK(view(ArrayDims{2})(Tag{}) == 2); +// // CHECK(view(ArrayDims{15})(Tag{}) == 15); +//} TEST_CASE("recorddim.int") {