aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorar7is7 <ar7is7@yandex-team.com>2022-12-23 13:04:52 +0300
committerar7is7 <ar7is7@yandex-team.com>2022-12-23 13:04:52 +0300
commit9c0a33e446c7a410d4f1f80cbea29e070841ddb4 (patch)
tree0aaf481dd264e9bb20fca7308c3cb64c261b7025
parente42806e60a2eab5a05348a0430b8e46b63cb0c9e (diff)
downloadydb-9c0a33e446c7a410d4f1f80cbea29e070841ddb4.tar.gz
Allow to use std::vector in AppendTo
-rw-r--r--library/cpp/getopt/small/last_getopt_opt.h6
-rw-r--r--library/cpp/getopt/ut/last_getopt_ut.cpp8
2 files changed, 10 insertions, 4 deletions
diff --git a/library/cpp/getopt/small/last_getopt_opt.h b/library/cpp/getopt/small/last_getopt_opt.h
index e8567bd4f6..5210b6e756 100644
--- a/library/cpp/getopt/small/last_getopt_opt.h
+++ b/library/cpp/getopt/small/last_getopt_opt.h
@@ -691,9 +691,9 @@ namespace NLastGetopt {
}
// Appends FromString<T>(arg) to *target for each argument
- template <typename T>
- TOpt& AppendTo(TVector<T>* target) {
- return Handler1T<T>([target](auto&& value) { target->push_back(std::move(value)); });
+ template<class Container>
+ TOpt& AppendTo(Container* target) {
+ return Handler1T<typename Container::value_type>([target](auto&& value) { target->push_back(std::move(value)); });
}
// Appends FromString<T>(arg) to *target for each argument
diff --git a/library/cpp/getopt/ut/last_getopt_ut.cpp b/library/cpp/getopt/ut/last_getopt_ut.cpp
index c2ee4f0c40..b517ea359d 100644
--- a/library/cpp/getopt/ut/last_getopt_ut.cpp
+++ b/library/cpp/getopt/ut/last_getopt_ut.cpp
@@ -736,15 +736,21 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) {
Y_UNIT_TEST(TestAppendTo) {
TVector<int> ints;
+ std::vector<std::string> strings;
TOptsNoDefault opts;
opts.AddLongOption("size").AppendTo(&ints);
+ opts.AddLongOption("value").AppendTo(&strings);
- TOptsParseResultTestWrapper r(&opts, V({"cmd", "--size=17", "--size=19"}));
+ TOptsParseResultTestWrapper r(&opts, V({"cmd", "--size=17", "--size=19", "--value=v1", "--value=v2"}));
UNIT_ASSERT_VALUES_EQUAL(size_t(2), ints.size());
UNIT_ASSERT_VALUES_EQUAL(17, ints.at(0));
UNIT_ASSERT_VALUES_EQUAL(19, ints.at(1));
+
+ UNIT_ASSERT_VALUES_EQUAL(size_t(2), strings.size());
+ UNIT_ASSERT_VALUES_EQUAL("v1", strings.at(0));
+ UNIT_ASSERT_VALUES_EQUAL("v2", strings.at(1));
}
Y_UNIT_TEST(TestEmplaceTo) {