Added support for std::string_view based path functions when using C++17

This commit is contained in:
gulrak 2019-03-26 00:47:35 -07:00
parent ec2bc5af0c
commit e49340a846
2 changed files with 29 additions and 9 deletions

View File

@ -311,9 +311,11 @@ path& operator+=(basic_string_view<value_type> x);
int compare(basic_string_view<value_type> s) const; int compare(basic_string_view<value_type> s) const;
``` ```
These are not implemented, as there is no `std::basic_string_view` available in These are not implemented under C++11 and C++14, as there is no
C++11 and I did want to keep this implementation self-contained and not `std::basic_string_view` available and I did want to keep this
write a full C++17-upgrade for C++11. implementation self-contained and not write a full C++17-upgrade for
C++11/14. Starting with v1.1.0 these are supported when compiling
ghc::filesystem under C++17.
### Differences in API ### Differences in API
@ -449,6 +451,8 @@ to the expected behavior.
additional simple includes are added, that can be used to forward additional simple includes are added, that can be used to forward
`ghc::filesystem` declarations (`fs_fwd.hpp`) and to wrap the `ghc::filesystem` declarations (`fs_fwd.hpp`) and to wrap the
implementation into a single cpp (`fs_impl.hpp`) implementation into a single cpp (`fs_impl.hpp`)
* The `std::basic_string_view` variants of the `fs::path` api are
now supported when compiling with C++17.
### [v1.0.10](https://github.com/gulrak/filesystem/releases/tag/v1.0.10) ### [v1.0.10](https://github.com/gulrak/filesystem/releases/tag/v1.0.10)

View File

@ -190,6 +190,12 @@ public:
struct _is_basic_string<std::basic_string<CharT, Traits, Alloc>> : std::true_type struct _is_basic_string<std::basic_string<CharT, Traits, Alloc>> : std::true_type
{ {
}; };
#ifdef __cpp_lib_string_view
template <class CharT>
struct _is_basic_string<std::basic_string_view<CharT>> : std::true_type
{
};
#endif
template <typename T1, typename T2 = void> template <typename T1, typename T2 = void>
using path_type = typename std::enable_if<!std::is_same<path, T1>::value, path>::type; using path_type = typename std::enable_if<!std::is_same<path, T1>::value, path>::type;
@ -237,7 +243,9 @@ public:
// 30.10.8.4.4 concatenation // 30.10.8.4.4 concatenation
path& operator+=(const path& x); path& operator+=(const path& x);
path& operator+=(const string_type& x); path& operator+=(const string_type& x);
// path& operator+=(basic_string_view<value_type> x); #ifdef __cpp_lib_string_view
path& operator+=(std::basic_string_view<value_type> x);
#endif
path& operator+=(const value_type* x); path& operator+=(const value_type* x);
path& operator+=(value_type x); path& operator+=(value_type x);
template <class Source> template <class Source>
@ -281,7 +289,9 @@ public:
// 30.10.8.4.8 compare // 30.10.8.4.8 compare
int compare(const path& p) const noexcept; int compare(const path& p) const noexcept;
int compare(const string_type& s) const; int compare(const string_type& s) const;
// int compare(basic_string_view<value_type> s) const; #ifdef __cpp_lib_string_view
int compare(std::basic_string_view<value_type> s) const;
#endif
int compare(const value_type* s) const; int compare(const value_type* s) const;
// 30.10.8.4.9 decomposition // 30.10.8.4.9 decomposition
@ -1947,7 +1957,12 @@ GHC_INLINE path& path::operator+=(const string_type& x)
return concat(x); return concat(x);
} }
// path& operator+=(basic_string_view<value_type> x); #ifdef __cpp_lib_string_view
GHC_INLINE path& path::operator+=(std::basic_string_view<value_type> x)
{
return concat(x);
}
#endif
GHC_INLINE path& path::operator+=(const value_type* x) GHC_INLINE path& path::operator+=(const value_type* x)
{ {
@ -2159,11 +2174,12 @@ GHC_INLINE int path::compare(const string_type& s) const
return native().compare(path(s).native()); return native().compare(path(s).native());
} }
/* #ifdef __cpp_lib_string_view
int path::compare(basic_string_view<value_type> s) const GHC_INLINE int path::compare(std::basic_string_view<value_type> s) const
{ {
return native().compare(path(s).native());
} }
*/ #endif
GHC_INLINE int path::compare(const value_type* s) const GHC_INLINE int path::compare(const value_type* s) const
{ {