alsk/tests/copy.cpp

76 lines
1.3 KiB
C++

#include <catch.hpp>
#include <alsk/alsk.h>
#include <numeric>
#include "common.h"
using namespace alsk;
namespace {
using Data = Measure<int>;
struct Opv {
template<typename... Ts>
void operator()(Ts&&...) {}
};
struct Op {
template<typename... Ts>
Data operator()(Ts&&...) { return {}; }
};
/* NOTE:
* `Data const&` causes a copy when then stored in Data
* to avoid: simply return `Data` instead or store in `Data&`
* hw uses one `auto` to enables this
*/
struct Opr {
template<typename... Ts>
Data const& operator()(Data const& a, Ts&&...) { return a; }
};
using Struct = S<Serial, Opv, Op, Opr, Op>;
using Links =
L<Serial, arg::R<3>(Data const&),
void(arg::P<0>),
Data(arg::P<0>),
Data(arg::R<1> const&),
Data(arg::P<0>, arg::R<1> const&, arg::R<2> const&)
>;
using Test = BuildSkeletonT<Struct, Links>;
void hw(Data const& p0) {
Opv{}(p0);
decltype(auto) r1 = Op{}(p0);
auto r2 = Opr{}(r1);
decltype(auto) r3 = Op{}(p0, r1, r2);
static_cast<void>(r3);
}
}
TEST_CASE("Copy") {
std::size_t bCopy, bMove, sCopy, sMove;
_copy = _move = 0;
hw({});
bCopy = _copy;
bMove = _move;
auto test = implement<exec::Sequential, Test>();
_copy = _move = 0;
test({});
sCopy = _copy;
sMove = _move;
CAPTURE(bCopy);
CAPTURE(sCopy);
REQUIRE(bCopy >= sCopy);
REQUIRE(bMove <= sMove);
}