Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use std::string_view and std::optional when possible
- Loading branch information
Jim Porter
committed
Jun 2, 2018
1 parent
91da7b3
commit a32cb7e
Showing
9 changed files
with
87 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,28 @@ | ||
#ifndef INC_METTLE_DRIVER_DETAIL_OPTIONAL_HPP | ||
#define INC_METTLE_DRIVER_DETAIL_OPTIONAL_HPP | ||
|
||
// Get _LIBCPP_VERSION to detect libc++. | ||
#include <ciso646> | ||
// Try to use std::optional, N4480's optional class, or fall back to Boost's. | ||
|
||
// Try to use N4480's optional class, or fall back to Boost's. | ||
#if defined(METTLE_USE_STDLIB_EXTS) | ||
# include <experimental/optional> | ||
# define METTLE_OPTIONAL_NS std::experimental | ||
#elif !defined(METTLE_NO_STDLIB_EXTS) && defined(__has_include) | ||
// XXX: clang doesn't support SFINAE in variadic templates, which libstdc++'s | ||
// `optional` relies on. See <https://llvm.org/bugs/show_bug.cgi?id=23840>. | ||
# if !(defined(__clang__) && !defined(_LIBCPP_VERSION) && \ | ||
defined(__GLIBCXX__)) && __has_include(<experimental/optional>) | ||
#ifdef __has_include | ||
# if __has_include(<optional>) && __cplusplus >= 201703L | ||
# include <optional> | ||
# define METTLE_OPTIONAL_NS std | ||
# elif __has_include(<experimental/optional>) && \ | ||
!defined(METTLE_NO_STDLIB_EXTS) | ||
# include <experimental/optional> | ||
# define METTLE_OPTIONAL_NS std::experimental | ||
# endif | ||
#endif | ||
|
||
#ifndef METTLE_OPTIONAL_NS | ||
# ifdef METTLE_USE_STDLIB_EXTS | ||
# include <experimental/optional> | ||
# define METTLE_OPTIONAL_NS std::experimental | ||
# else | ||
# include <boost/optional.hpp> | ||
# include <boost/optional/optional_io.hpp> | ||
# define METTLE_OPTIONAL_NS boost | ||
# endif | ||
#else | ||
# include <boost/optional.hpp> | ||
# include <boost/optional/optional_io.hpp> | ||
# define METTLE_OPTIONAL_NS boost | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef INC_METTLE_OUTPUT_DETAIL_STRING_VIEW_HPP | ||
#define INC_METTLE_OUTPUT_DETAIL_STRING_VIEW_HPP | ||
|
||
// Try to use std::string_view, N4480's version, or fall back to Boost's. | ||
|
||
#ifdef __has_include | ||
# if __has_include(<string_view>) && __cplusplus >= 201703L | ||
# include <string_view> | ||
# define METTLE_STRING_VIEW std::basic_string_view | ||
# elif __has_include(<experimental/string_view>) && \ | ||
!defined(METTLE_NO_STDLIB_EXTS) | ||
# include <experimental/string_view> | ||
# define METTLE_STRING_VIEW std::experimental::basic_string_view | ||
# endif | ||
#endif | ||
|
||
#ifndef METTLE_STRING_VIEW | ||
# ifdef METTLE_USE_STDLIB_EXTS | ||
# include <experimental/string_view> | ||
# define METTLE_STRING_VIEW std::experimental::basic_string_view | ||
# else | ||
# include <boost/version.hpp> | ||
# if BOOST_VERSION >= 106100 | ||
# include <boost/utility/string_view.hpp> | ||
# define METTLE_STRING_VIEW boost::basic_string_view | ||
# else | ||
# include <boost/utility/string_ref.hpp> | ||
# define METTLE_STRING_VIEW boost::basic_string_ref | ||
# endif | ||
# endif | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters