-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
optional_fwd.hpp
50 lines (37 loc) · 1.03 KB
/
optional_fwd.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
Copyright (C) 2020 by the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
#include "global.hpp"
#ifdef HAVE_CXX17
#include <optional>
#else
#include <boost/optional.hpp>
#endif
namespace utils
{
#ifdef HAVE_CXX17
using std::optional;
using std::nullopt;
#else
using boost::optional;
// Create a new nullopt object equivalent to boost::none to match the STL interface
static const boost::none_t nullopt{boost::none_t::init_tag{}};
#endif
template<typename T>
bool has_optional_value(const optional<T>& opt)
{
#if defined HAVE_CXX17 || BOOST_VERSION >= 106800
return opt.has_value();
#else
return opt != nullopt;
#endif
}
} // end namespace utils