Skip to content

Commit

Permalink
ARROW-6552: [C++] boost::optional in STL test fails compiling in gcc …
Browse files Browse the repository at this point in the history
…4.8.2

It is reported in the mailgroup that string literals aren't implicitly convertible to `boost::optional<std::string>` in some old versions of gcc, causing compilation errors. This patch wraps such literals used in test cases with `std::string`.

Closes apache#5369 from ozars/arrow-6552 and squashes the following commits:

dc05f31 <Benjamin Kietzman> Merge branch 'arrow-6552' of github.com:ozars/arrow into arrow-6552
94ea09f <Benjamin Kietzman> format string literal operator acceptably for gcc 4.8.2
c866809 <Omer Ozarslan> Make tuple constructors explicit
3d27eaf <Omer Ozarslan> Wrap string literals with std::string

Lead-authored-by: Omer Ozarslan <[email protected]>
Co-authored-by: Benjamin Kietzman <[email protected]>
Signed-off-by: Benjamin Kietzman <[email protected]>
  • Loading branch information
ozars and bkietz committed Sep 13, 2019
1 parent 40718ba commit 5bc0fda
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
4 changes: 3 additions & 1 deletion cpp/src/arrow/dataset/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ inline std::shared_ptr<FieldExpression> field_ref(std::string name) {
}

inline namespace string_literals {
inline FieldExpression operator""_(const char* name, size_t name_length) {
// clang-format off
inline FieldExpression operator"" _(const char* name, size_t name_length) {
// clang-format on
return FieldExpression({name, name_length});
}
} // namespace string_literals
Expand Down
5 changes: 4 additions & 1 deletion cpp/src/arrow/dataset/filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
namespace arrow {
namespace dataset {

using string_literals::operator""_;
// clang-format off
using string_literals::operator"" _;
// clang-format on

using internal::checked_cast;
using internal::checked_pointer_cast;

Expand Down
21 changes: 12 additions & 9 deletions cpp/src/arrow/stl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,9 @@ TEST(TestTableFromTupleVector, ReferenceTuple) {

std::vector<std::string> names{"column1", "column2", "column3", "column4", "column5",
"column6", "column7", "column8", "column9", "column10"};
std::vector<CustomType> rows{{-1, -2, -3, -4, 1, 2, 3, 4, true, "Tests"},
{-10, -20, -30, -40, 10, 20, 30, 40, false, "Other"}};
std::vector<CustomType> rows{
{-1, -2, -3, -4, 1, 2, 3, 4, true, std::string("Tests")},
{-10, -20, -30, -40, 10, 20, 30, 40, false, std::string("Other")}};
auto rng_rows =
transform(rows, [](const CustomType& c) -> decltype(c.tie()) { return c.tie(); });
std::shared_ptr<Table> table;
Expand Down Expand Up @@ -290,8 +291,8 @@ TEST(TestTableFromTupleVector, NullableTypesWithBoostOptional) {
"column6", "column7", "column8", "column9", "column10"};
using types_tuple = boost_optional_types_tuple;
std::vector<types_tuple> rows{
types_tuple(-1, -2, -3, -4, 1, 2, 3, 4, true, "Tests"),
types_tuple(-10, -20, -30, -40, 10, 20, 30, 40, false, "Other"),
types_tuple(-1, -2, -3, -4, 1, 2, 3, 4, true, std::string("Tests")),
types_tuple(-10, -20, -30, -40, 10, 20, 30, 40, false, std::string("Other")),
types_tuple(boost::none, boost::none, boost::none, boost::none, boost::none,
boost::none, boost::none, boost::none, boost::none, boost::none),
};
Expand Down Expand Up @@ -329,8 +330,9 @@ TEST(TestTableFromTupleVector, NullableTypesWithRawPointer) {
std::vector<std::string> names{"column1", "column2", "column3", "column4", "column5",
"column6", "column7", "column8", "column9", "column10"};
std::vector<primitive_types_tuple> data_rows{
primitive_types_tuple(-1, -2, -3, -4, 1, 2, 3, 4, true, "Tests"),
primitive_types_tuple(-10, -20, -30, -40, 10, 20, 30, 40, false, "Other"),
primitive_types_tuple(-1, -2, -3, -4, 1, 2, 3, 4, true, std::string("Tests")),
primitive_types_tuple(-10, -20, -30, -40, 10, 20, 30, 40, false,
std::string("Other")),
};
std::vector<raw_pointer_optional_types_tuple> pointer_rows;
for (auto& row : data_rows) {
Expand Down Expand Up @@ -388,10 +390,11 @@ TEST(TestTableFromTupleVector, NullableTypesDoNotBreakUserSpecialization) {
}

TEST(TestTableFromTupleVector, AppendingMultipleRows) {
using row_type = std::tuple<std::vector<TestInt32Type>>;
std::vector<std::string> names{"column1"};
std::vector<std::tuple<std::vector<TestInt32Type>>> rows = {
{{{1}, {2}, {3}}}, //
{{{10}, {20}, {30}}} //
std::vector<row_type> rows = {
row_type{{{1}, {2}, {3}}}, //
row_type{{{10}, {20}, {30}}} //
};
std::shared_ptr<Table> table;
ASSERT_OK(TableFromTupleRange(default_memory_pool(), rows, names, &table));
Expand Down

0 comments on commit 5bc0fda

Please sign in to comment.