summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-09-05 02:14:40 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-12-17 15:36:04 +0000
commit388918afc582f562afd9942bd19e70b7e7f2bb8e (patch)
treed4b8f3889521f6e6416185d3aa65c94fefbbe066
parentconstexpr string_view some more stuff (diff)
downloadicespider-388918afc582f562afd9942bd19e70b7e7f2bb8e.tar.bz2
icespider-388918afc582f562afd9942bd19e70b7e7f2bb8e.tar.xz
icespider-388918afc582f562afd9942bd19e70b7e7f2bb8e.zip
Add contains to flatmap
-rw-r--r--icespider/core/flatMap.h12
-rw-r--r--icespider/fcgi/cgiRequestBase.cpp2
-rw-r--r--icespider/unittests/testFlatMap.cpp9
3 files changed, 22 insertions, 1 deletions
diff --git a/icespider/core/flatMap.h b/icespider/core/flatMap.h
index 33e1f24..e23bd46 100644
--- a/icespider/core/flatMap.h
+++ b/icespider/core/flatMap.h
@@ -18,6 +18,11 @@ namespace IceSpider {
{
return c(v.first, n);
}
+ bool
+ operator()(const N & n, const V & v) const
+ {
+ return c(n, v.first);
+ }
Comp c;
};
@@ -43,6 +48,13 @@ namespace IceSpider {
template<typename N>
auto
+ contains(const N & n) const
+ {
+ return std::binary_search(begin(), end(), n, KeyComp<N> {});
+ }
+
+ template<typename N>
+ auto
find(const N & n) const
{
const auto lb = lower_bound(n);
diff --git a/icespider/fcgi/cgiRequestBase.cpp b/icespider/fcgi/cgiRequestBase.cpp
index 7d746b8..a1c804b 100644
--- a/icespider/fcgi/cgiRequestBase.cpp
+++ b/icespider/fcgi/cgiRequestBase.cpp
@@ -170,7 +170,7 @@ namespace IceSpider {
bool
CgiRequestBase::isSecure() const
{
- return envmap.find(HTTPS) != envmap.end();
+ return envmap.contains(HTTPS);
}
OptionalString
diff --git a/icespider/unittests/testFlatMap.cpp b/icespider/unittests/testFlatMap.cpp
index 12d6900..c2fcea4 100644
--- a/icespider/unittests/testFlatMap.cpp
+++ b/icespider/unittests/testFlatMap.cpp
@@ -16,6 +16,7 @@ BOOST_AUTO_TEST_CASE(is_empty)
BOOST_CHECK(empty());
BOOST_CHECK_EQUAL(find(""), end());
+ BOOST_CHECK(!contains(""));
}
BOOST_AUTO_TEST_CASE(single)
@@ -24,6 +25,9 @@ BOOST_AUTO_TEST_CASE(single)
BOOST_CHECK_EQUAL(size(), 1);
BOOST_CHECK(!empty());
+ BOOST_CHECK(!contains(""));
+ BOOST_CHECK(contains("a"));
+ BOOST_CHECK(!contains("b"));
BOOST_CHECK_EQUAL(begin()->first, "a");
BOOST_CHECK_EQUAL(begin()->second, 1);
BOOST_CHECK_EQUAL(find("a"), begin());
@@ -42,6 +46,11 @@ BOOST_AUTO_TEST_CASE(several)
BOOST_CHECK_EQUAL(size(), 3);
BOOST_CHECK(!empty());
+ BOOST_CHECK(!contains(""));
+ BOOST_CHECK(contains("a"));
+ BOOST_CHECK(!contains("b"));
+ BOOST_CHECK(contains("c"));
+ BOOST_CHECK(contains("f"));
BOOST_CHECK_EQUAL(begin()->first, "a");
BOOST_CHECK_EQUAL(begin()->second, 1);
BOOST_CHECK_EQUAL(find("a"), begin());