Skip to content

Commit

Permalink
Use C++11 language features unconditionally.
Browse files Browse the repository at this point in the history
Use nullptr, rvalue references, default function template parameters,
deleted/defaulted functions, noexcept, final, override and scoped enums.

Don't use constexpr yet, as it would raise MSVC requirement.
  • Loading branch information
Lastique committed Jan 13, 2024
1 parent fc24312 commit 2781bbe
Show file tree
Hide file tree
Showing 22 changed files with 466 additions and 615 deletions.
12 changes: 6 additions & 6 deletions include/boost/filesystem/cstdio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ inline std::FILE* fopen(filesystem::path const& p, const char* mode)
wchar_t buf[128u];
wchar_t* p;

small_array() BOOST_NOEXCEPT : p(buf) {}
~small_array() BOOST_NOEXCEPT
small_array() noexcept : p(buf) {}
~small_array() noexcept
{
if (BOOST_UNLIKELY(p != buf))
std::free(p);
Expand All @@ -52,18 +52,18 @@ inline std::FILE* fopen(filesystem::path const& p, const char* mode)
std::size_t wmode_len = std::mbstowcs(wmode.p, mode, sizeof(wmode.buf) / sizeof(wchar_t));
if (BOOST_UNLIKELY(wmode_len >= (sizeof(wmode.buf) / sizeof(wchar_t))))
{
wmode_len = std::mbstowcs(NULL, mode, 0u);
wmode_len = std::mbstowcs(nullptr, mode, 0u);
// Check for size overflow, including (size_t)-1, which indicates mbstowcs error
if (BOOST_UNLIKELY(wmode_len >= (static_cast< std::size_t >(-1) / sizeof(wchar_t))))
return NULL;
return nullptr;

wmode.p = static_cast< wchar_t* >(std::malloc((wmode_len + 1u) * sizeof(wchar_t)));
if (BOOST_UNLIKELY(!wmode.p))
return NULL;
return nullptr;

std::size_t wmode_len2 = std::mbstowcs(wmode.p, mode, wmode_len + 1u);
if (BOOST_UNLIKELY(wmode_len2 > wmode_len))
return NULL;
return nullptr;
}

return ::_wfopen(p.c_str(), wmode.p);
Expand Down
26 changes: 10 additions & 16 deletions include/boost/filesystem/detail/path_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ template< typename, typename, typename > class basic_string;

namespace filesystem {

BOOST_FILESYSTEM_DECL system::error_category const& codecvt_error_category() BOOST_NOEXCEPT;
BOOST_FILESYSTEM_DECL system::error_category const& codecvt_error_category() noexcept;

class directory_entry;

Expand Down Expand Up @@ -398,19 +398,19 @@ struct is_native_char_ptr< const path_native_char_type* > :
};


//! Converts character encoding using the supplied codecvt facet. If \a cvt is \c NULL then \c path::codecvt() will be used.
//! Converts character encoding using the supplied codecvt facet. If \a cvt is \c nullptr then \c path::codecvt() will be used.
BOOST_FILESYSTEM_DECL
void convert(const char* from, const char* from_end, std::wstring& to, const codecvt_type* cvt = NULL);
void convert(const char* from, const char* from_end, std::wstring& to, const codecvt_type* cvt = nullptr);

//! \overload convert
BOOST_FILESYSTEM_DECL
void convert(const wchar_t* from, const wchar_t* from_end, std::string& to, const codecvt_type* cvt = NULL);
void convert(const wchar_t* from, const wchar_t* from_end, std::string& to, const codecvt_type* cvt = nullptr);


// Source dispatch -----------------------------------------------------------------//

template< typename Source, typename Callback >
typename Callback::result_type dispatch(Source const& source, Callback cb, const codecvt_type* cvt = NULL);
typename Callback::result_type dispatch(Source const& source, Callback cb, const codecvt_type* cvt = nullptr);

template< typename Callback >
BOOST_FORCEINLINE typename Callback::result_type dispatch(const char* source, Callback cb, const codecvt_type* cvt, ntcts_type_tag)
Expand Down Expand Up @@ -442,7 +442,7 @@ BOOST_FORCEINLINE typename Callback::result_type dispatch(Source const& source,
template< typename Callback >
BOOST_FORCEINLINE typename Callback::result_type dispatch(std::vector< char > const& source, Callback cb, const codecvt_type* cvt, range_type_tag)
{
const char* data = NULL, *data_end = NULL;
const char* data = nullptr, *data_end = nullptr;
if (!source.empty())
{
data = &source[0];
Expand All @@ -454,7 +454,7 @@ BOOST_FORCEINLINE typename Callback::result_type dispatch(std::vector< char > co
template< typename Callback >
BOOST_FORCEINLINE typename Callback::result_type dispatch(std::vector< wchar_t > const& source, Callback cb, const codecvt_type* cvt, range_type_tag)
{
const wchar_t* data = NULL, *data_end = NULL;
const wchar_t* data = nullptr, *data_end = nullptr;
if (!source.empty())
{
data = &source[0];
Expand Down Expand Up @@ -496,9 +496,7 @@ yes_type check_convertible(std::wstring_view const&);
#endif
yes_type check_convertible(boost::basic_string_view< char, std::char_traits< char > > const&);
yes_type check_convertible(boost::basic_string_view< wchar_t, std::char_traits< wchar_t > > const&);
#if !defined(BOOST_NO_CXX11_NULLPTR)
no_type check_convertible(std::nullptr_t);
#endif
no_type check_convertible(...);

} // namespace is_convertible_to_path_source_impl
Expand All @@ -525,9 +523,7 @@ namespace is_convertible_to_std_string_view_impl {

yes_type check_convertible(std::string_view const&);
yes_type check_convertible(std::wstring_view const&);
#if !defined(BOOST_NO_CXX11_NULLPTR)
no_type check_convertible(std::nullptr_t);
#endif
no_type check_convertible(...);

} // namespace is_convertible_to_std_string_view_impl
Expand All @@ -551,9 +547,7 @@ yes_type check_convertible(boost::container::basic_string< char, std::char_trait
yes_type check_convertible(boost::container::basic_string< wchar_t, std::char_traits< wchar_t >, void > const&);
yes_type check_convertible(boost::basic_string_view< char, std::char_traits< char > > const&);
yes_type check_convertible(boost::basic_string_view< wchar_t, std::char_traits< wchar_t > > const&);
#if !defined(BOOST_NO_CXX11_NULLPTR)
no_type check_convertible(std::nullptr_t);
#endif
no_type check_convertible(...);

} // namespace is_convertible_to_path_source_non_std_string_view_impl
Expand Down Expand Up @@ -683,7 +677,7 @@ BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible_impl(std::
#endif // !defined(BOOST_NO_CXX17_HDR_STRING_VIEW)

template< typename Source, typename Callback >
BOOST_FORCEINLINE typename Callback::result_type dispatch_convertible(Source const& source, Callback cb, const codecvt_type* cvt = NULL)
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;
return path_traits::dispatch_convertible_impl< source_t >(source, cb, cvt);
Expand All @@ -709,7 +703,7 @@ 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,
typename Callback::result_type
>::type dispatch_convertible(Source const& source, Callback cb, const codecvt_type* cvt = NULL)
>::type dispatch_convertible(Source const& source, Callback cb, const codecvt_type* cvt = nullptr)
{
typedef typename boost::remove_cv< Source >::type source_t;
return path_traits::dispatch_convertible_impl< source_t >(source, cb, cvt);
Expand All @@ -719,7 +713,7 @@ 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,
typename Callback::result_type
>::type dispatch_convertible(Source const& source, Callback cb, const codecvt_type* cvt = NULL)
>::type dispatch_convertible(Source const& source, Callback cb, const codecvt_type* cvt = nullptr)
{
typedef typename boost::remove_cv< Source >::type source_t;
return path_traits::dispatch_convertible_sv_impl< source_t >(source, cb, cvt);
Expand Down
Loading

0 comments on commit 2781bbe

Please sign in to comment.