Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrongly defined Blob concept #659

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix wrongly defined Blob concept
The previous definition only did a syntax check but did not evaluate the expression.
  • Loading branch information
bernhardmgruber committed Dec 15, 2022
commit 4bd78dc5534f07dbff0e2103ab9e1700dc9a828c
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