szaszm commented on code in PR #1589:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1589#discussion_r1265169957
##########
libminifi/src/core/Property.cpp:
##########
@@ -90,4 +94,41 @@ std::vector<std::pair<std::string, std::string>>
Property::getExclusiveOfPropert
return exclusive_of_properties_;
}
+namespace {
+std::vector<PropertyValue> createPropertyValues(gsl::span<const
std::string_view> values, const core::PropertyParser& property_parser) {
+ return ranges::views::transform(values, [&property_parser](const auto&
value) {
+ return property_parser.parse(value);
+ }) | ranges::to<std::vector>;
+}
+
+inline std::vector<std::string> createStrings(gsl::span<const
std::string_view> string_views) {
+ return ranges::views::transform(string_views, [](const auto& string_view) {
return std::string{string_view}; })
+ | ranges::to<std::vector>;
+}
+
+inline std::vector<std::pair<std::string, std::string>>
createStrings(gsl::span<const std::pair<std::string_view, std::string_view>>
pairs_of_string_views) {
+ return ranges::views::transform(pairs_of_string_views, [](const auto&
pair_of_string_views) { return std::pair<std::string,
std::string>(pair_of_string_views); })
+ | ranges::to<std::vector>;
+}
+} // namespace
+
+Property::Property(const PropertyReference& compile_time_property)
+ : name_(compile_time_property.name),
+ description_(compile_time_property.description),
+ is_required_(compile_time_property.is_required),
+ valid_regex_(compile_time_property.valid_regex),
Review Comment:
I would remove it, and on the off chance that this breaks anyone's workflow,
we can always revert it.
##########
libminifi/test/unit/ArrayUtilsTests.cpp:
##########
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "../Catch.h"
+#include "utils/ArrayUtils.h"
+
+namespace utils = org::apache::nifi::minifi::utils;
+
+TEST_CASE("array_cat() works correctly and is constexpr") {
+ static constexpr auto empty = std::array<int, 0>{};
+ static constexpr auto one_to_three = std::array{1, 2, 3};
+ static constexpr auto four_to_five = utils::array_cat(empty, std::array{4,
5});
+ static constexpr auto all = utils::array_cat(one_to_three, empty,
four_to_five, empty);
+ static_assert(all == std::array{1, 2, 3, 4, 5});
+}
+
+TEST_CASE("string_view_to_array() works correctly and is constexpr") {
+ static constexpr std::string_view hello = "Hello world!";
+ static constexpr auto hello_array =
utils::string_view_to_array<hello.size()>(hello);
+ static_assert(std::string_view{hello_array.data(), hello_array.size()} ==
"Hello world!");
+
+ static constexpr auto hello_again = utils::array_to_string_view(hello_array);
+ static_assert(hello_again == "Hello world!");
+}
+
+TEST_CASE("getKeys() works correctly and is constexpr") {
+ static constexpr std::array<std::pair<std::string_view, int>, 3> mapping{{
{"one", 1}, {"two", 2}, {"three", 3} }};
+ static constexpr auto keys = utils::getKeys(mapping);
+ static_assert(keys == std::array<std::string_view, 3>{"one", "two",
"three"});
+}
+
+TEST_CASE("at() works correctly and is constexpr") {
+ static constexpr std::array<std::pair<int, std::string_view>, 3> mapping{{
{1, "one"}, {2, "two"}, {3, "three"} }};
+ static constexpr auto two = utils::at(mapping, 2);
+ static_assert(two == "two");
+
+ int one = 1;
+ CHECK(utils::at(mapping, one) == "one"); // non-constexpr argument is OK,
but the result is not constexpr
+
+ // static constexpr auto four = utils::at(mapping, 4); // does not compile
Review Comment:
Could we check that this doesn't compile using SFINAE or concepts? I used
something similar in GeneralUtilsTest to test constexpr `intdiv_ceil`. That one
was in 2020, so it hacks around `std::enable_if`, but I think `std::void_t`
would also work now, or a single-use concept definition.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]