Skip to content

Commit

Permalink
Fix wrongly defined Blob concept
Browse files Browse the repository at this point in the history
The previous definition only did a syntax check but did not evaluate the expression.
  • Loading branch information
bernhardmgruber committed Dec 15, 2022
1 parent 38ebb45 commit 4bd78dc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/memmap/memmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ auto main(int argc, const char* argv[]) -> int

// memory map the teapot geometry file
auto file = boost::iostreams::mapped_file_source(argv[1]);
const char* content = file.data();
const auto* content = reinterpret_cast<const std::byte*>(file.data());
const auto size = file.size();

// binary STL header is 80 bytes, followed by uint32 triangle count, followed by vertex data without padding
Expand Down
7 changes: 4 additions & 3 deletions include/llama/Concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ namespace llama
template <typename M>
concept PartiallyComputedMapping = Mapping<M> && allFieldsArePhysicalOrComputed<M>;

// according to http://eel.is/c++draft/intro.object#3 only std::byte and unsigned char can provide storage for
// other types
template<typename B>
concept Blob = requires(B b, std::size_t i) {
// according to http://eel.is/c++draft/intro.object#3 only std::byte and unsigned char can provide storage for
// other types
std::is_same_v<decltype(b[i]), std::byte&> || std::is_same_v<decltype(b[i]), unsigned char&>;
requires std::is_same_v<std::remove_cvref_t<decltype(b[i])>, std::byte> ||
std::is_same_v<std::remove_cvref_t<decltype(b[i])>, unsigned char>;
};

template <typename BA>
Expand Down
18 changes: 18 additions & 0 deletions tests/bloballocators.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
#include "common.hpp"

#include <memory>
#include <vector>

using ArrayExtents = llama::ArrayExtents<int, 16>;
using Mapping = llama::mapping::AoS<ArrayExtents, Vec3I>;

TEST_CASE("blob.concept")
{
#ifdef __cpp_lib_concepts
STATIC_REQUIRE(llama::Blob<llama::Array<std::byte, 10>>);
STATIC_REQUIRE(llama::Blob<llama::Array<unsigned char, 10>>);
STATIC_REQUIRE(!llama::Blob<llama::Array<char, 10>>);
STATIC_REQUIRE(!llama::Blob<llama::Array<double, 10>>);

STATIC_REQUIRE(llama::Blob<std::vector<std::byte>>);
STATIC_REQUIRE(llama::Blob<std::unique_ptr<std::byte[]>>);
STATIC_REQUIRE(llama::Blob<std::shared_ptr<std::byte[]>>);
STATIC_REQUIRE(llama::Blob<std::byte*>);
#endif
}

TEST_CASE("bloballocators.Array")
{
constexpr auto mapping = Mapping{{}};
Expand Down

0 comments on commit 4bd78dc

Please sign in to comment.