add std::clamp
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
/**
|
||||
* Predefined Symbols for C++
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2016 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2016-2017 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
* http://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
* @file nana/config.hpp
|
||||
* @file nana/c++defines.hpp
|
||||
*
|
||||
* @brief Provide switches to adapt to the target OS, use of external libraries or workarounds compiler errors or lack of std C++ support.
|
||||
*
|
||||
@@ -31,13 +31,14 @@
|
||||
* - _SCL_SECURE_NO_WARNNGS, _CRT_SECURE_NO_DEPRECATE (VC)
|
||||
* - STD_CODECVT_NOT_SUPPORTED (VC RC, <codecvt> is a known issue on libstdc++, it works on libc++)
|
||||
* - STD_THREAD_NOT_SUPPORTED (GCC < 4.8.1)
|
||||
* - STD_put_time_NOT_SUPPORTED (GCC < 5)
|
||||
* - STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED (MinGW with GCC < 4.8.1)
|
||||
* - STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED (MinGW with GCC < 4.8.1)
|
||||
* - STD_TO_STRING_NOT_SUPPORTED (MinGW with GCC < 4.8)
|
||||
* - STD_FILESYSTEM_NOT_SUPPORTED (GCC < 5.3) ....
|
||||
* - CXX_NO_INLINE_NAMESPACE (Visual C++ < 2015)
|
||||
* - STD_MAKE_UNIQUE_NOT_SUPPORTED (GCC < 4.9)
|
||||
* - _enable_std_make_unique (GCC < 4.9)
|
||||
* - _enable_std_put_time (GCC < 5)
|
||||
* - _enable_std_clamp (Visual C++ < 2017)
|
||||
*/
|
||||
|
||||
#ifndef NANA_CXX_DEFINES_INCLUDED
|
||||
@@ -57,7 +58,7 @@
|
||||
# define CXX_NO_INLINE_NAMESPACE //no support of C++11 inline namespace until Visual C++ 2015
|
||||
# define noexcept //no support of noexcept until Visual C++ 2015
|
||||
|
||||
# define constexpr const //no support of constexpr until Visual C++ 2015 ? const ??
|
||||
# define constexpr //no support of constexpr until Visual C++ 2015 ? const ??
|
||||
# else
|
||||
# undef STD_FILESYSTEM_NOT_SUPPORTED
|
||||
# endif
|
||||
@@ -102,14 +103,18 @@
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
#pragma warning(disable : 4996)
|
||||
|
||||
#if (_MSC_VER >= 1900)
|
||||
# if (_MSC_VER >= 1900)
|
||||
// google: break any code that tries to use codecvt<char16_t> or codecvt<char32_t>.
|
||||
// google: It appears the C++ libs haven't been compiled with native char16_t/char32_t support.
|
||||
// google: Those definitions are for codecvt<wchar_t>::id, codecvt<unsigned short>::id and codecvt<char>::id respectively.
|
||||
// However, the codecvt<char16_t>::id and codecvt<char32_t>::id definitions aren't there, and indeed, if you look at locale0.cpp in the CRT source code you'll see they're not defined at all.
|
||||
// google: That's a known issue, tracked by an active bug (DevDiv#1060849). We were able to update the STL's headers in response to char16_t/char32_t, but we still need to update the separately compiled sources.
|
||||
#define STD_CODECVT_NOT_SUPPORTED
|
||||
#endif // _MSC_VER == 1900
|
||||
# define STD_CODECVT_NOT_SUPPORTED
|
||||
# endif // _MSC_VER == 1900
|
||||
|
||||
# if (_MSC_VER < 1910) //VS2017 RTM
|
||||
# define _enable_std_clamp
|
||||
# endif
|
||||
|
||||
#elif defined(__clang__) //Clang
|
||||
|
||||
@@ -119,13 +124,15 @@
|
||||
#define STD_CODECVT_NOT_SUPPORTED
|
||||
|
||||
#if !defined(__cpp_lib_make_unique) || (__cpp_lib_make_unique != 201304)
|
||||
#ifndef STD_MAKE_UNIQUE_NOT_SUPPORTED
|
||||
#define STD_MAKE_UNIQUE_NOT_SUPPORTED
|
||||
#ifndef _enable_std_make_unique
|
||||
#define _enable_std_make_unique
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
# define _enable_std_clamp
|
||||
|
||||
#elif defined(__GNUC__) //GCC
|
||||
|
||||
#include <iosfwd> //Introduces some implement-specific flags of ISO C++ Library
|
||||
@@ -145,9 +152,9 @@
|
||||
#endif
|
||||
|
||||
|
||||
#if ((__GNUC__ < 5) )
|
||||
# define STD_put_time_NOT_SUPPORTED
|
||||
#endif
|
||||
# if ((__GNUC__ < 5) )
|
||||
# define _enable_std_put_time
|
||||
# endif
|
||||
|
||||
#if ((__GNUC__ > 5) || ((__GNUC__ == 5) && (__GNUC_MINOR__ >= 3 ) ) )
|
||||
# undef STD_FILESYSTEM_NOT_SUPPORTED
|
||||
@@ -160,7 +167,7 @@
|
||||
#endif
|
||||
|
||||
#if (__GNUC_MINOR__ < 9)
|
||||
#define STD_MAKE_UNIQUE_NOT_SUPPORTED
|
||||
#define _enable_std_make_unique
|
||||
#endif
|
||||
|
||||
#if defined(NANA_MINGW)
|
||||
@@ -181,6 +188,8 @@
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
# define _enable_std_clamp
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -17,98 +17,12 @@
|
||||
#include <nana/push_ignore_diagnostic>
|
||||
|
||||
#include <nana/config.hpp>
|
||||
#include <nana/stdc++.hpp>
|
||||
|
||||
|
||||
#include <stdexcept>
|
||||
#include <nana/charset.hpp>
|
||||
|
||||
//Implement workarounds for GCC/MinGW which version is below 4.8.2
|
||||
#if defined(STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED)
|
||||
namespace std
|
||||
{
|
||||
//Workaround for no implemenation of std::stoi in MinGW.
|
||||
int stoi(const std::string&, std::size_t * pos = nullptr, int base = 10);
|
||||
int stoi(const std::wstring&, std::size_t* pos = nullptr, int base = 10);
|
||||
|
||||
//Workaround for no implemenation of std::stof in MinGW.
|
||||
float stof(const std::string&, std::size_t * pos = nullptr);
|
||||
float stof(const std::wstring&, std::size_t* pos = nullptr);
|
||||
|
||||
//Workaround for no implemenation of std::stod in MinGW.
|
||||
double stod(const std::string&, std::size_t * pos = nullptr);
|
||||
double stod(const std::wstring&, std::size_t* pos = nullptr);
|
||||
|
||||
//Workaround for no implemenation of std::stold in MinGW.
|
||||
long double stold(const std::string&, std::size_t * pos = nullptr);
|
||||
long double stold(const std::wstring&, std::size_t* pos = nullptr);
|
||||
|
||||
//Workaround for no implemenation of std::stol in MinGW.
|
||||
long stol(const std::string&, std::size_t* pos = nullptr, int base = 10);
|
||||
long stol(const std::wstring&, std::size_t* pos = nullptr, int base = 10);
|
||||
|
||||
//Workaround for no implemenation of std::stoll in MinGW.
|
||||
long long stoll(const std::string&, std::size_t* pos = nullptr, int base = 10);
|
||||
long long stoll(const std::wstring&, std::size_t* pos = nullptr, int base = 10);
|
||||
|
||||
//Workaround for no implemenation of std::stoul in MinGW.
|
||||
unsigned long stoul(const std::string&, std::size_t* pos = nullptr, int base = 10);
|
||||
unsigned long stoul(const std::wstring&, std::size_t* pos = nullptr, int base = 10);
|
||||
|
||||
//Workaround for no implemenation of std::stoull in MinGW.
|
||||
unsigned long long stoull(const std::string&, std::size_t* pos = nullptr, int base = 10);
|
||||
unsigned long long stoull(const std::wstring&, std::size_t* pos = nullptr, int base = 10);
|
||||
}
|
||||
#endif //STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED
|
||||
|
||||
#ifdef STD_TO_STRING_NOT_SUPPORTED
|
||||
namespace std
|
||||
{
|
||||
//Workaround for no implemenation of std::to_string/std::to_wstring in MinGW.
|
||||
std::string to_string(long double);
|
||||
std::string to_string(double);
|
||||
std::string to_string(unsigned);
|
||||
std::string to_string(int);
|
||||
std::string to_string(long);
|
||||
std::string to_string(unsigned long);
|
||||
std::string to_string(long long);
|
||||
std::string to_string(unsigned long long);
|
||||
std::string to_string(float);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef STD_TO_WSTRING_NOT_SUPPORTED
|
||||
namespace std
|
||||
{
|
||||
std::wstring to_wstring(long double);
|
||||
std::wstring to_wstring(double);
|
||||
std::wstring to_wstring(unsigned);
|
||||
std::wstring to_wstring(int);
|
||||
std::wstring to_wstring(long);
|
||||
std::wstring to_wstring(unsigned long);
|
||||
std::wstring to_wstring(long long);
|
||||
std::wstring to_wstring(unsigned long long);
|
||||
std::wstring to_wstring(float);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef STD_put_time_NOT_SUPPORTED
|
||||
#include <ctime>
|
||||
namespace std
|
||||
{
|
||||
//Workaround for no implemenation of std::put_time in gcc < 5.
|
||||
/* std unspecified return type */
|
||||
//template< class CharT, class RTSTR >// let fail for CharT != char / wchar_t
|
||||
//RTSTR put_time(const std::tm* tmb, const CharT* fmt);
|
||||
|
||||
//template< >
|
||||
std::string put_time/*<char, std::string>*/(const std::tm* tmb, const char* fmt);
|
||||
|
||||
//Defined in header <ctime>
|
||||
// std::size_t strftime(char* str, std::size_t count, const char* format, const std::tm* time);
|
||||
//template<>
|
||||
//std::wstring put_time<wchar_t, std::wstring>(const std::tm* tmb, const wchar_t* fmt);
|
||||
}
|
||||
#endif // STD_put_time_NOT_SUPPORTED
|
||||
|
||||
namespace nana
|
||||
{
|
||||
@@ -192,45 +106,5 @@ namespace nana
|
||||
|
||||
#define NANA_RGB(a) (((DWORD)(a) & 0xFF)<<16) | ((DWORD)(a) & 0xFF00) | (((DWORD)(a) & 0xFF0000) >> 16 )
|
||||
|
||||
|
||||
#ifdef STD_MAKE_UNIQUE_NOT_SUPPORTED
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3656.htm
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace std {
|
||||
template<class T> struct _Unique_if {
|
||||
typedef unique_ptr<T> _Single_object;
|
||||
};
|
||||
|
||||
template<class T> struct _Unique_if<T[]> {
|
||||
typedef unique_ptr<T[]> _Unknown_bound;
|
||||
};
|
||||
|
||||
template<class T, size_t N> struct _Unique_if<T[N]> {
|
||||
typedef void _Known_bound;
|
||||
};
|
||||
|
||||
template<class T, class... Args>
|
||||
typename _Unique_if<T>::_Single_object
|
||||
make_unique(Args&&... args) {
|
||||
return unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
typename _Unique_if<T>::_Unknown_bound
|
||||
make_unique(size_t n) {
|
||||
typedef typename remove_extent<T>::type U;
|
||||
return unique_ptr<T>(new U[n]());
|
||||
}
|
||||
|
||||
template<class T, class... Args>
|
||||
typename _Unique_if<T>::_Known_bound
|
||||
make_unique(Args&&...) = delete;
|
||||
}
|
||||
#endif //STD_make_unique_NOT_SUPPORTED
|
||||
#include <nana/pop_ignore_diagnostic>
|
||||
#endif //NANA_DEPLOY_HPP
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -23,13 +23,13 @@ namespace filesystem_ext
|
||||
{
|
||||
|
||||
#if defined(NANA_WINDOWS)
|
||||
constexpr auto def_root = "C:";
|
||||
constexpr auto def_rootstr = "C:\\";
|
||||
constexpr auto def_rootname = "Local Drive(C:)";
|
||||
constexpr auto const def_root = "C:";
|
||||
constexpr auto const def_rootstr = "C:\\";
|
||||
constexpr auto const def_rootname = "Local Drive(C:)";
|
||||
#elif defined(NANA_LINUX)
|
||||
constexpr auto def_root = "/";
|
||||
constexpr auto def_rootstr = "/";
|
||||
constexpr auto def_rootname = "Root/";
|
||||
constexpr auto const def_root = "/";
|
||||
constexpr auto const def_rootstr = "/";
|
||||
constexpr auto const def_rootname = "Root/";
|
||||
#endif
|
||||
|
||||
std::experimental::filesystem::path path_user(); ///< extention ?
|
||||
|
||||
@@ -647,7 +647,7 @@ namespace nana
|
||||
/// usefull for both absolute and display (sorted) positions
|
||||
struct index_pair
|
||||
{
|
||||
constexpr static size_type npos = ::nana::npos;
|
||||
constexpr static const size_type npos = ::nana::npos;
|
||||
|
||||
size_type cat; //The pos of category
|
||||
size_type item; //the pos of item in a category.
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace nana
|
||||
{
|
||||
std::unique_ptr<Interface> create() override
|
||||
{
|
||||
constexpr auto Size = std::tuple_size<decltype(args_)>::value;
|
||||
constexpr auto const Size = std::tuple_size<decltype(args_)>::value;
|
||||
return std::unique_ptr<Interface>{ _m_new(make_pack<Size>{}) };
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
#pragma message ( SHOW_VALUE(USE_github_com_meganz_mingw_std_threads) )
|
||||
#pragma message ( SHOW_VALUE(NANA_ENABLE_MINGW_STD_THREADS_WITH_MEGANZ) )
|
||||
#pragma message ( SHOW_VALUE(STD_THREAD_NOT_SUPPORTED) )
|
||||
#pragma message ( SHOW_VALUE(STD_put_time_NOT_SUPPORTED) )
|
||||
#pragma message ( SHOW_VALUE(_enable_std_put_time) )
|
||||
#pragma message ( SHOW_VALUE(STD_MAKE_UNIQUE_NOT_SUPPORTED) )
|
||||
|
||||
#pragma message ( SHOW_VALUE(STD_FILESYSTEM_NOT_SUPPORTED) )
|
||||
|
||||
Reference in New Issue
Block a user