Skip to content

Commit 29b9ca1

Browse files
committed
Use std::variant instead of boost::variant if available
1 parent 5aea3bf commit 29b9ca1

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

include/osmium/util/string_matcher.hpp

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ DEALINGS IN THE SOFTWARE.
3333
3434
*/
3535

36-
#include <boost/variant.hpp>
37-
3836
#include <algorithm>
3937
#include <cstring>
4038
#include <iosfwd>
@@ -43,6 +41,17 @@ DEALINGS IN THE SOFTWARE.
4341
#include <utility>
4442
#include <vector>
4543

44+
#ifdef __has_include
45+
# if __has_include(<variant>)
46+
# include <variant>
47+
# define OSMIUM_USE_STD_VARIANT
48+
# endif
49+
#else
50+
# include <boost/variant.hpp>
51+
# define OSMIUM_USE_BOOST_VARIANT
52+
#endif
53+
54+
4655
// std::regex isn't implemented properly in glibc++ (before the version
4756
// delivered with GCC 4.9) and libc++ before the version 3.6, so the use is
4857
// disabled by these checks. Checks for GLIBC were based on
@@ -270,19 +279,29 @@ namespace osmium {
270279

271280
private:
272281

273-
using matcher_type = boost::variant<always_false,
274-
always_true,
275-
equal,
276-
prefix,
277-
substring,
282+
using matcher_type =
283+
#ifdef OSMIUM_USE_STD_VARIANT
284+
std::variant
285+
#else
286+
boost::variant
287+
#endif
288+
<always_false,
289+
always_true,
290+
equal,
291+
prefix,
292+
substring,
278293
#ifdef OSMIUM_WITH_REGEX
279-
regex,
294+
regex,
280295
#endif
281-
list>;
296+
list>;
282297

283298
matcher_type m_matcher;
284299

285-
class match_visitor : public boost::static_visitor<bool> {
300+
class match_visitor
301+
#ifdef OSMIUM_USE_BOOST_VARIANT
302+
: public boost::static_visitor<bool>
303+
#endif
304+
{
286305

287306
const char* m_str;
288307

@@ -300,7 +319,11 @@ namespace osmium {
300319
}; // class match_visitor
301320

302321
template <typename TChar, typename TTraits>
303-
class print_visitor : public boost::static_visitor<void> {
322+
class print_visitor
323+
#ifdef OSMIUM_USE_BOOST_VARIANT
324+
: public boost::static_visitor<void>
325+
#endif
326+
{
304327

305328
std::basic_ostream<TChar, TTraits>* m_out;
306329

@@ -403,7 +426,11 @@ namespace osmium {
403426
* Match the specified string.
404427
*/
405428
bool operator()(const char* str) const noexcept {
429+
#ifdef OSMIUM_USE_STD_VARIANT
430+
return std::visit(match_visitor{str}, m_matcher);
431+
#else
406432
return boost::apply_visitor(match_visitor{str}, m_matcher);
433+
#endif
407434
}
408435

409436
/**
@@ -415,7 +442,11 @@ namespace osmium {
415442

416443
template <typename TChar, typename TTraits>
417444
void print(std::basic_ostream<TChar, TTraits>& out) const {
445+
#ifdef OSMIUM_USE_STD_VARIANT
446+
std::visit(print_visitor<TChar, TTraits>{out}, m_matcher);
447+
#else
418448
boost::apply_visitor(print_visitor<TChar, TTraits>{out}, m_matcher);
449+
#endif
419450
}
420451

421452
}; // class StringMatcher
@@ -428,4 +459,7 @@ namespace osmium {
428459

429460
} // namespace osmium
430461

462+
#undef OSMIUM_USE_STD_VARIANT
463+
#undef OSMIUM_USE_BOOST_VARIANT
464+
431465
#endif // OSMIUM_UTIL_STRING_MATCHER_HPP

0 commit comments

Comments
 (0)