-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change interface to require Input and Output types.
- Loading branch information
Showing
21 changed files
with
414 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,44 @@ | ||
#ifndef JASMIN_CORE_INPUT_H | ||
#define JASMIN_CORE_INPUT_H | ||
|
||
#include <tuple> | ||
|
||
#include "jasmin/core/value.h" | ||
#include "nth/meta/sequence.h" | ||
#include "nth/meta/type.h" | ||
|
||
namespace jasmin { | ||
namespace internal { | ||
struct InputBase {}; | ||
} // namespace internal | ||
|
||
template <typename... Ts> | ||
struct in { | ||
requires((std::constructible_from<Value, Ts> and ...)) // | ||
struct Input : internal::InputBase { | ||
static constexpr int count = sizeof...(Ts); | ||
|
||
explicit constexpr Input(Value const *ptr) : ptr_(ptr) {} | ||
|
||
template <int N> | ||
auto get() { | ||
return (ptr_ + N * sizeof(Value)) | ||
->as<nth::type_t<types.template get<N>()>>(); | ||
constexpr auto get() { | ||
return ptr_[N].as<nth::type_t<types.template get<N>()>>(); | ||
} | ||
|
||
private: | ||
static constexpr auto types = nth::type_sequence<Ts...>; | ||
Value *ptr_; | ||
Value const *ptr_; | ||
}; | ||
|
||
} // namespace jasmin | ||
|
||
template <typename... Ts> | ||
struct std::tuple_size<::jasmin::Input<Ts...>> | ||
: std::integral_constant<size_t, sizeof...(Ts)> {}; | ||
|
||
template <size_t N, typename... Ts> | ||
struct std::tuple_element<N, ::jasmin::Input<Ts...>> { | ||
using type = | ||
decltype(std::declval<::jasmin::Input<Ts...>>().template get<N>()); | ||
}; | ||
|
||
#endif // JASMIN_CORE_INPUT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "jasmin/core/input.h" | ||
|
||
#include "nth/test/test.h" | ||
|
||
namespace jasmin { | ||
namespace { | ||
|
||
static_assert(Input<>::count == 0); | ||
static_assert(Input<int>::count == 1); | ||
static_assert(Input<int, bool>::count == 2); | ||
static_assert(Input<int, int>::count == 2); | ||
|
||
NTH_TEST("input/single") { | ||
Value vs[1]; | ||
vs[0] = 3; | ||
Input<int> input(vs); | ||
NTH_EXPECT(input.get<0>() == 3); | ||
auto [n] = input; | ||
NTH_EXPECT(n == 3); | ||
} | ||
|
||
NTH_TEST("input/multiple") { | ||
Value vs[2]; | ||
vs[0] = 3; | ||
vs[1] = true; | ||
Input<int, bool> input(vs); | ||
NTH_EXPECT(input.get<0>() == 3); | ||
NTH_EXPECT(input.get<1>()); | ||
auto [n, b] = input; | ||
NTH_EXPECT(n == 3); | ||
NTH_EXPECT(b); | ||
} | ||
|
||
} // namespace | ||
} // namespace jasmin |
Oops, something went wrong.