Skip to content

Commit cb6e213

Browse files
[needs discussion] replace load() with conversion operator
1 parent a13ecd4 commit cb6e213

File tree

2 files changed

+19
-39
lines changed

2 files changed

+19
-39
lines changed

include/llama/View.hpp

+6-26
Original file line numberDiff line numberDiff line change
@@ -708,36 +708,16 @@ namespace llama
708708
std::make_index_sequence<std::tuple_size_v<decltype(asFlatTuple())>>{});
709709
}
710710

711-
struct Loader
712-
{
713-
VirtualDatum& vd;
714-
715-
template <typename T>
716-
operator T()
717-
{
718-
return vd.loadAs<T>();
719-
}
720-
};
721-
722-
struct LoaderConst
723-
{
724-
const VirtualDatum& vd;
725-
726-
template <typename T>
727-
operator T() const
728-
{
729-
return vd.loadAs<T>();
730-
}
731-
};
732-
733-
auto load() -> Loader
711+
template <typename T>
712+
operator T()
734713
{
735-
return {*this};
714+
return loadAs<T>();
736715
}
737716

738-
auto load() const -> LoaderConst
717+
template <typename T>
718+
operator T() const
739719
{
740-
return {*this};
720+
return loadAs<T>();
741721
}
742722

743723
// template <typename = std::enable_if_t<supportsValueLoad>>

tests/virtualdatum.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -693,24 +693,24 @@ struct std::tuple_size<MyDatum<T>>
693693
static constexpr std::size_t value = 3;
694694
};
695695

696-
TEST_CASE("VirtualDatum.load.value")
696+
TEST_CASE("VirtualDatum.convert.value")
697697
{
698698
llama::One<Name> datum;
699699
datum = 1;
700700

701701
{
702-
MyPos<int> pos = datum(tag::Pos{}).load();
702+
MyPos<int> pos = datum(tag::Pos{});
703703
CHECK(pos.a == 1);
704704
CHECK(pos.y == 1);
705705
}
706706
{
707-
MyPos<int> pos = std::as_const(datum)(tag::Pos{}).load();
707+
MyPos<int> pos = std::as_const(datum)(tag::Pos{});
708708
CHECK(pos.a == 1);
709709
CHECK(pos.y == 1);
710710
}
711711

712712
{
713-
MyDatum<int> d = datum.load();
713+
MyDatum<int> d = datum;
714714
CHECK(d.pos.a == 1);
715715
CHECK(d.pos.y == 1);
716716
CHECK(d.vel.x == 1);
@@ -719,7 +719,7 @@ TEST_CASE("VirtualDatum.load.value")
719719
CHECK(d.weight == 1);
720720
}
721721
{
722-
MyDatum<int> d = std::as_const(datum).load();
722+
MyDatum<int> d = std::as_const(datum);
723723
CHECK(d.pos.a == 1);
724724
CHECK(d.pos.y == 1);
725725
CHECK(d.vel.x == 1);
@@ -729,13 +729,13 @@ TEST_CASE("VirtualDatum.load.value")
729729
}
730730
}
731731

732-
TEST_CASE("VirtualDatum.load.ref")
732+
TEST_CASE("VirtualDatum.convert.ref")
733733
{
734734
llama::One<Name> datum;
735735

736736
datum = 1;
737737
{
738-
MyPos<int&> pos = datum(tag::Pos{}).load();
738+
MyPos<int&> pos = datum(tag::Pos{});
739739
CHECK(pos.a == 1);
740740
CHECK(pos.y == 1);
741741

@@ -751,7 +751,7 @@ TEST_CASE("VirtualDatum.load.ref")
751751

752752
datum = 1;
753753
{
754-
MyDatum<int&> d = datum.load();
754+
MyDatum<int&> d = datum;
755755
CHECK(d.pos.a == 1);
756756
CHECK(d.pos.y == 1);
757757

@@ -770,28 +770,28 @@ TEST_CASE("VirtualDatum.load.ref")
770770
}
771771
}
772772

773-
TEST_CASE("VirtualDatum.load.constref")
773+
TEST_CASE("VirtualDatum.convert.constref")
774774
{
775775
llama::One<Name> datum;
776776
datum = 1;
777777

778778
{
779-
MyPos<const int&> pos = datum(tag::Pos{}).load();
779+
MyPos<const int&> pos = datum(tag::Pos{});
780780
CHECK(pos.a == 1);
781781
CHECK(pos.y == 1);
782782
}
783783
{
784-
MyPos<const int&> pos = std::as_const(datum)(tag::Pos{}).load();
784+
MyPos<const int&> pos = std::as_const(datum)(tag::Pos{});
785785
CHECK(pos.a == 1);
786786
CHECK(pos.y == 1);
787787
}
788788
{
789-
MyDatum<const int&> d = datum.load();
789+
MyDatum<const int&> d = datum;
790790
CHECK(d.pos.a == 1);
791791
CHECK(d.pos.y == 1);
792792
}
793793
{
794-
MyDatum<const int&> d = std::as_const(datum).load();
794+
MyDatum<const int&> d = std::as_const(datum);
795795
CHECK(d.pos.a == 1);
796796
CHECK(d.pos.y == 1);
797797
}

0 commit comments

Comments
 (0)