Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Leibner
dune-common
Commits
d953de45
Commit
d953de45
authored
7 years ago
by
Tobias Malkmus
Browse files
Options
Downloads
Patches
Plain Diff
[optinal] use std::optional on newer compilers
parent
ffd4ea39
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmake/modules/CheckCXXFeatures.cmake
+18
-0
18 additions, 0 deletions
cmake/modules/CheckCXXFeatures.cmake
config.h.cmake
+3
-0
3 additions, 0 deletions
config.h.cmake
dune/common/std/optional.hh
+17
-0
17 additions, 0 deletions
dune/common/std/optional.hh
with
38 additions
and
0 deletions
cmake/modules/CheckCXXFeatures.cmake
+
18
−
0
View file @
d953de45
...
...
@@ -22,6 +22,9 @@
# :code:`DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION`
# True if C++17's class template argument deduction is supported
#
# :code:`DUNE_HAVE_CXX_OPTIONAL`
# True if C++17's optional implementation is supported
#
# .. cmake_variable:: DISABLE_CXX_VERSION_CHECK
#
# You may set this variable to TRUE to disable checking for
...
...
@@ -350,6 +353,21 @@ check_cxx_source_compiles("
"
DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
)
# support for C++17's optional implementation
check_cxx_source_compiles
(
"
#include <optional>
#include <string>
int main()
{
std::optional< std::string > a;
std::string b = a.value_or(
\"
empty
\"
);
}
"
DUNE_HAVE_CXX_OPTIONAL
)
# find the threading library
# Use a copy FindThreads from CMake 3.1 due to its support of pthread
if
(
NOT DEFINED THREADS_PREFER_PTHREAD_FLAG
)
...
...
This diff is collapsed.
Click to expand it.
config.h.cmake
+
3
−
0
View file @
d953de45
...
...
@@ -29,6 +29,9 @@
/* does the compiler support C++17's class template argument deduction? */
#cmakedefine DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 1
/* does the compiler support C++17's optional? */
#cmakedefine DUNE_HAVE_CXX_OPTIONAL 1
/* does the compiler support conditionally throwing exceptions in constexpr context? */
#cmakedefine DUNE_SUPPORTS_CXX_THROW_IN_CONSTEXPR 1
...
...
This diff is collapsed.
Click to expand it.
dune/common/std/optional.hh
+
17
−
0
View file @
d953de45
...
...
@@ -7,12 +7,24 @@
#include
<type_traits>
#include
<utility>
#ifdef DUNE_HAVE_CXX_OPTIONAL
#include
<optional>
#endif // #ifdef DUNE_HAVE_CXX_OPTIONAL
namespace
Dune
{
namespace
Std
{
#ifdef DUNE_HAVE_CXX_OPTIONAL
// In case of C++ standard >= 17 we forward optionals into our namespace
template
<
class
T
>
using
optional
=
std
::
optional
<
T
>
;
#else
// In case of C++ standard < 17 we take the fallback implementation
// nullopt
// -------
...
...
@@ -414,11 +426,14 @@ namespace Dune
return
optional
<
typename
std
::
decay
<
T
>::
type
>
(
std
::
forward
<
T
>
(
value
)
);
}
#endif //#ifdef DUNE_HAVE_CXX_OPTIONAL
}
// namespace Std
}
// namespace Dune
#ifndef DUNE_HAVE_CXX_OPTIONAL
namespace
std
{
...
...
@@ -447,4 +462,6 @@ namespace std
}
// namespace std
#endif //#ifndef DUNE_HAVE_CXX_OPTIONAL
#endif // #ifndef DUNE_COMMON_STD_OPTIONAL_HH
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment