Skip to content

Commit

Permalink
DataTable::NewRow(Raw&&)
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Jul 8, 2024
1 parent e6baf71 commit 0ac53c4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions include/momo/DataTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,13 @@ class DataTable
return pvNewRow(assign, assigns...);
}

template<typename RawArg = Raw>
Row NewRow(RawArg&& rawArg)
requires requires (ColumnList& columnList, MemManager& memManager, Raw* raw)
{ columnList.CreateRaw(memManager, std::forward<RawArg>(rawArg), raw); }
Row NewRow(std::conditional_t<std::is_void_v<Raw>, void*, Raw>&& srcRaw) //?
requires (!std::is_void_v<Raw>) &&
requires (ColumnList& columnList, MemManager& memManager, Raw* raw)
{ columnList.CreateRaw(memManager, std::move(srcRaw), raw); }
{
auto rawCreator = [this, &rawArg] (Raw* raw)
{ GetColumnList().CreateRaw(GetMemManager(), std::forward<RawArg>(rawArg), raw); };
auto rawCreator = [this, &srcRaw] (Raw* raw)
{ GetColumnList().CreateRaw(GetMemManager(), std::move(srcRaw), raw); };
return pvMakeRow(pvCreateRaw(FastMovableFunctor(std::move(rawCreator))));
}

Expand Down
8 changes: 4 additions & 4 deletions test/sources/SimpleDataSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace sample_data2
// unique index (primary key)
table.AddUniqueHashIndex(&Struct::strCol, &Struct::intCol);

table.AddRow(table.NewRow(Struct{ .intCol = 1, .dblCol = 0.5, .strCol = "b" }));
table.AddRow(table.NewRow({ .intCol = 1, .dblCol = 0.5, .strCol = "b" }));

{
auto row = table.NewRow();
Expand All @@ -102,7 +102,7 @@ namespace sample_data2
table.TryAddRow(std::move(row)); // strCol = ""
}

table.TryAddRow(table.NewRow(Struct{ .intCol = 1, .dblCol = 3.5, .strCol = "b" }));
table.TryAddRow(table.NewRow({ .intCol = 1, .dblCol = 3.5, .strCol = "b" }));
// not added because of unique index

output << table.GetCount() << std::endl; // 2
Expand Down Expand Up @@ -282,8 +282,8 @@ namespace sample_data5
// construct empty table with 3 columns
Table table;

table.AddRow(table.NewRow(Struct{ .intCol = 1, .dblCol = 1.5, .strCol = "a" }));
table.AddRow(table.NewRow(Struct{ .intCol = 2, .strCol = "a" }));
table.AddRow(table.NewRow({ .intCol = 1, .dblCol = 1.5, .strCol = "a" }));
table.AddRow(table.NewRow({ .intCol = 2, .strCol = "a" }));

for (auto row : table)
output << row->intCol << " " << row->dblCol << " " << row->strCol << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion test/sources/SimpleDataTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ class SimpleDataTester

if constexpr (!dynamic)
{
Row row = table.NewRow(Struct{ .intStruct = 1, .dblStruct = 3.5, .strStruct = "2" });
Row row = table.NewRow({ .intStruct = 1, .dblStruct = 3.5, .strStruct = "2" });
assert(row->intStruct == 1);
assert(row->dblStruct == 3.5);
assert(row->strStruct == "2");
Expand Down

0 comments on commit 0ac53c4

Please sign in to comment.