Apache Log4cxx
Version 1.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
optional.h
Go to the documentation of this file.
1
/*
2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*/
17
18
#ifndef LOG4CXX_OPTIONAL_HDR_
19
#define LOG4CXX_OPTIONAL_HDR_
20
21
#ifdef __has_include
// Check if __has_include is present
22
# if __has_include(<optional>)
// Check for a standard version
23
# include <optional>
24
# if defined(__cpp_lib_optional)
// C++ >= 17
25
namespace
LOG4CXX_NS {
template
<
class
T >
using
Optional = std::optional<T>; }
26
#define LOG4CXX_HAS_STD_OPTIONAL 1
27
# endif
28
# elif __has_include(<experimental/optional>)
// Check for an experimental version
29
# include <experimental/optional>
30
namespace
LOG4CXX_NS {
template
<
class
T >
using
Optional = std::experimental::optional<T>; }
31
#define LOG4CXX_HAS_STD_OPTIONAL 1
32
# elif __has_include(<boost/optional.hpp>)
// Try with an external library
33
# include <boost/optional.hpp>
34
namespace
LOG4CXX_NS {
template
<
class
T >
using
Optional = boost::optional<T>; }
35
#define LOG4CXX_HAS_STD_OPTIONAL 1
36
# else
// Not found at all
37
#define LOG4CXX_HAS_STD_OPTIONAL 0
38
# endif
39
#endif
40
41
#if !LOG4CXX_HAS_STD_OPTIONAL
// Implement a minimal Optional?
42
namespace
LOG4CXX_NS
43
{
44
template
<
class
T >
45
class
Optional
:
private
std::pair<bool, T>
46
{
47
using
BaseType = std::pair<bool, T>;
48
public
:
49
Optional
() : BaseType(false, T()) {}
50
Optional
&
operator=
(
const
T&
value
)
51
{
52
this->first =
true
;
53
this->second =
value
;
54
return
*
this
;
55
}
56
constexpr
explicit
operator
bool() const noexcept {
return
this->first; }
57
constexpr
bool
has_value
() const noexcept {
return
this->first; }
58
constexpr
const
T&
value
() const noexcept {
return
this->second; }
59
};
60
}
// namespace LOG4CXX_NS
61
#endif
62
63
#endif
// LOG4CXX_OPTIONAL_HDR_
log4cxx::Optional::operator=
Optional & operator=(const T &value)
Definition
optional.h:50
log4cxx::Optional::has_value
constexpr bool has_value() const noexcept
Definition
optional.h:57
log4cxx::Optional::value
constexpr const T & value() const noexcept
Definition
optional.h:58
log4cxx::Optional::Optional
Optional()
Definition
optional.h:49
src
main
include
log4cxx
helpers
optional.h
Generated by
1.17.0 on
SITE_PUBLISHED_DATE
Copyright © 2017-2026
Apache Software Foundation
. Apache, Chainsaw, log4cxx, Log4j, Log4net, log4php and the Apache logo are
trademarks or registered trademarks
of The Apache Software Foundation.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
Privacy Policy
.