Skip to content

Commit

Permalink
Use <type_traits>, when possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lastique committed Feb 19, 2024
1 parent 46af0a9 commit 7bdccb0
Show file tree
Hide file tree
Showing 5 changed files with 339 additions and 191 deletions.
79 changes: 41 additions & 38 deletions include/boost/filesystem/detail/path_traits.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// filesystem path_traits.hpp --------------------------------------------------------//

// Copyright Beman Dawes 2009
// Copyright Andrey Semashev 2022
// Copyright Andrey Semashev 2022-2024

// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
Expand All @@ -18,19 +18,16 @@
#include <locale>
#include <string>
#include <iterator>
#include <type_traits>
#if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)
#include <string_view>
#endif
#include <boost/assert.hpp>
#include <boost/system/error_category.hpp>
#include <boost/iterator/is_iterator.hpp>
#include <boost/type_traits/declval.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/conjunction.hpp>
#include <boost/filesystem/detail/type_traits/conjunction.hpp>
#if defined(BOOST_FILESYSTEM_DETAIL_CXX23_STRING_VIEW_HAS_IMPLICIT_RANGE_CTOR)
#include <boost/type_traits/disjunction.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/filesystem/detail/type_traits/disjunction.hpp>
#endif
#if defined(BOOST_FILESYSTEM_DEPRECATED) && BOOST_FILESYSTEM_VERSION < 4
#include <vector>
Expand Down Expand Up @@ -315,13 +312,13 @@ struct path_source_traits< directory_entry >
//! The trait tests if the type is a known path Source tag
template< typename Tag >
struct is_known_path_source_tag :
public boost::true_type
public std::true_type
{
};

template< >
struct is_known_path_source_tag< unknown_type_tag > :
public boost::false_type
public std::false_type
{
};

Expand All @@ -336,27 +333,27 @@ struct is_path_source :
//! The trait indicates whether the type is a path Source that is natively supported by path::string_type as the source for construction/assignment/appending
template< typename T >
struct is_native_path_source :
public boost::integral_constant< bool, path_source_traits< T >::is_native >
public std::integral_constant< bool, path_source_traits< T >::is_native >
{
};


//! The trait indicates whether the type is one of the supported path character types
template< typename T >
struct is_path_char_type :
public boost::false_type
public std::false_type
{
};

template< >
struct is_path_char_type< char > :
public boost::true_type
public std::true_type
{
};

template< >
struct is_path_char_type< wchar_t > :
public boost::true_type
public std::true_type
{
};

Expand All @@ -370,30 +367,33 @@ struct is_iterator_to_path_chars :
//! The trait indicates whether the type is an iterator over a sequence of path characters
template< typename Iterator >
struct is_path_source_iterator :
public boost::conjunction<
boost::iterators::is_iterator< Iterator >,
is_iterator_to_path_chars< Iterator >
>::type
public std::integral_constant<
bool,
detail::conjunction<
boost::iterators::is_iterator< Iterator >,
is_iterator_to_path_chars< Iterator >
>::value
>
{
};


//! The trait indicates whether the type is a pointer to a sequence of native path characters
template< typename T >
struct is_native_char_ptr :
public boost::false_type
public std::false_type
{
};

template< >
struct is_native_char_ptr< path_native_char_type* > :
public boost::true_type
public std::true_type
{
};

template< >
struct is_native_char_ptr< const path_native_char_type* > :
public boost::true_type
public std::true_type
{
};

Expand Down Expand Up @@ -473,7 +473,7 @@ template< typename Source, typename Callback >
BOOST_FORCEINLINE typename Callback::result_type dispatch(Source const& source, Callback cb, const codecvt_type* cvt)
{
return path_traits::dispatch(source, cb, cvt,
typename path_traits::path_source_traits< typename boost::remove_cv< Source >::type >::tag_type());
typename path_traits::path_source_traits< typename std::remove_cv< Source >::type >::tag_type());
}


Expand Down Expand Up @@ -504,9 +504,9 @@ no_type check_convertible(...);
//! The type trait indicates whether the type has a conversion path to one of the path source types
template< typename T >
struct is_convertible_to_path_source :
public boost::integral_constant<
public std::integral_constant<
bool,
sizeof(is_convertible_to_path_source_impl::check_convertible(boost::declval< T const& >())) == sizeof(yes_type)
sizeof(is_convertible_to_path_source_impl::check_convertible(std::declval< T const& >())) == sizeof(yes_type)
>
{
};
Expand All @@ -530,9 +530,9 @@ no_type check_convertible(...);

template< typename T >
struct is_convertible_to_std_string_view :
public boost::integral_constant<
public std::integral_constant<
bool,
sizeof(is_convertible_to_std_string_view_impl::check_convertible(boost::declval< T const& >())) == sizeof(yes_type)
sizeof(is_convertible_to_std_string_view_impl::check_convertible(std::declval< T const& >())) == sizeof(yes_type)
>
{
};
Expand All @@ -554,20 +554,23 @@ no_type check_convertible(...);

template< typename T >
struct is_convertible_to_path_source_non_std_string_view :
public boost::integral_constant<
public std::integral_constant<
bool,
sizeof(is_convertible_to_path_source_non_std_string_view_impl::check_convertible(boost::declval< T const& >())) == sizeof(yes_type)
sizeof(is_convertible_to_path_source_non_std_string_view_impl::check_convertible(std::declval< T const& >())) == sizeof(yes_type)
>
{
};

//! The type trait indicates whether the type has a conversion path to one of the path source types
template< typename T >
struct is_convertible_to_path_source :
public boost::disjunction<
is_convertible_to_std_string_view< T >,
is_convertible_to_path_source_non_std_string_view< T >
>::type
public std::integral_constant<
bool,
detail::disjunction<
is_convertible_to_std_string_view< T >,
is_convertible_to_path_source_non_std_string_view< T >
>::value
>
{
};

Expand Down Expand Up @@ -679,7 +682,7 @@ BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl(std::
template< typename Source, typename Callback >
BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible(Source const& source, Callback cb, const codecvt_type* cvt = nullptr)
{
typedef typename boost::remove_cv< Source >::type source_t;
typedef typename std::remove_cv< Source >::type source_t;
return path_traits::dispatch_convertible_impl< source_t >(source, cb, cvt);
}

Expand All @@ -700,22 +703,22 @@ BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_sv_impl(st
}

template< typename Source, typename Callback >
BOOST_FORCEINLINE typename boost::disable_if_c<
is_convertible_to_std_string_view< typename boost::remove_cv< Source >::type >::value,
BOOST_FORCEINLINE typename std::enable_if<
!is_convertible_to_std_string_view< typename std::remove_cv< Source >::type >::value,
typename Callback::result_type
>::type dispatch_convertible(Source const& source, Callback cb, const codecvt_type* cvt = nullptr)
{
typedef typename boost::remove_cv< Source >::type source_t;
typedef typename std::remove_cv< Source >::type source_t;
return path_traits::dispatch_convertible_impl< source_t >(source, cb, cvt);
}

template< typename Source, typename Callback >
BOOST_FORCEINLINE typename boost::enable_if_c<
is_convertible_to_std_string_view< typename boost::remove_cv< Source >::type >::value,
BOOST_FORCEINLINE typename std::enable_if<
is_convertible_to_std_string_view< typename std::remove_cv< Source >::type >::value,
typename Callback::result_type
>::type dispatch_convertible(Source const& source, Callback cb, const codecvt_type* cvt = nullptr)
{
typedef typename boost::remove_cv< Source >::type source_t;
typedef typename std::remove_cv< Source >::type source_t;
return path_traits::dispatch_convertible_sv_impl< source_t >(source, cb, cvt);
}

Expand Down
49 changes: 49 additions & 0 deletions include/boost/filesystem/detail/type_traits/conjunction.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* https://www.boost.org/LICENSE_1_0.txt)
*
* Copyright (c) 2024 Andrey Semashev
*/
/*!
* \file filesystem/detail/type_traits/conjunction.hpp
*
* This header contains definition of \c conjunction type trait.
*/

#ifndef BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_CONJUNCTION_HPP_INCLUDED_
#define BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_CONJUNCTION_HPP_INCLUDED_

#include <type_traits>
#include <boost/filesystem/config.hpp>

#if (defined(__cpp_lib_logical_traits) && (__cpp_lib_logical_traits >= 201510l)) || \
(defined(BOOST_MSSTL_VERSION) && (BOOST_MSSTL_VERSION >= 140) && (_MSC_FULL_VER >= 190023918) && (BOOST_CXX_VERSION >= 201703l))

namespace boost {
namespace filesystem {
namespace detail {

using std::conjunction;

} // namespace detail
} // namespace filesystem
} // namespace boost

#else

#include <boost/type_traits/conjunction.hpp>

namespace boost {
namespace filesystem {
namespace detail {

using boost::conjunction;

} // namespace detail
} // namespace filesystem
} // namespace boost

#endif

#endif // BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_CONJUNCTION_HPP_INCLUDED_
49 changes: 49 additions & 0 deletions include/boost/filesystem/detail/type_traits/disjunction.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* https://www.boost.org/LICENSE_1_0.txt)
*
* Copyright (c) 2024 Andrey Semashev
*/
/*!
* \file filesystem/detail/type_traits/disjunction.hpp
*
* This header contains definition of \c disjunction type trait.
*/

#ifndef BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_DISJUNCTION_HPP_INCLUDED_
#define BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_DISJUNCTION_HPP_INCLUDED_

#include <type_traits>
#include <boost/filesystem/config.hpp>

#if (defined(__cpp_lib_logical_traits) && (__cpp_lib_logical_traits >= 201510l)) || \
(defined(BOOST_MSSTL_VERSION) && (BOOST_MSSTL_VERSION >= 140) && (_MSC_FULL_VER >= 190023918) && (BOOST_CXX_VERSION >= 201703l))

namespace boost {
namespace filesystem {
namespace detail {

using std::disjunction;

} // namespace detail
} // namespace filesystem
} // namespace boost

#else

#include <boost/type_traits/disjunction.hpp>

namespace boost {
namespace filesystem {
namespace detail {

using boost::disjunction;

} // namespace detail
} // namespace filesystem
} // namespace boost

#endif

#endif // BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_DISJUNCTION_HPP_INCLUDED_
49 changes: 49 additions & 0 deletions include/boost/filesystem/detail/type_traits/negation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* https://www.boost.org/LICENSE_1_0.txt)
*
* Copyright (c) 2024 Andrey Semashev
*/
/*!
* \file filesystem/detail/type_traits/negation.hpp
*
* This header contains definition of \c negation type trait.
*/

#ifndef BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_NEGATION_HPP_INCLUDED_
#define BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_NEGATION_HPP_INCLUDED_

#include <type_traits>
#include <boost/filesystem/config.hpp>

#if (defined(__cpp_lib_logical_traits) && (__cpp_lib_logical_traits >= 201510l)) || \
(defined(BOOST_MSSTL_VERSION) && (BOOST_MSSTL_VERSION >= 140) && (_MSC_FULL_VER >= 190023918) && (BOOST_CXX_VERSION >= 201703l))

namespace boost {
namespace filesystem {
namespace detail {

using std::negation;

} // namespace detail
} // namespace filesystem
} // namespace boost

#else

#include <boost/type_traits/negation.hpp>

namespace boost {
namespace filesystem {
namespace detail {

using boost::negation;

} // namespace detail
} // namespace filesystem
} // namespace boost

#endif

#endif // BOOST_FILESYSTEM_DETAIL_TYPE_TRAITS_NEGATION_HPP_INCLUDED_
Loading

0 comments on commit 7bdccb0

Please sign in to comment.