mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Initial solution
This commit is contained in:
parent
fe6fd35174
commit
cd273e777d
@ -35,7 +35,6 @@ SOFTWARE.
|
||||
#include "algorithm.h"
|
||||
#include "iterator.h"
|
||||
#include "functional.h"
|
||||
#include "char_traits.h"
|
||||
#include "alignment.h"
|
||||
#include "array.h"
|
||||
#include "type_traits.h"
|
||||
@ -2697,39 +2696,6 @@ namespace etl
|
||||
return to;
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// get_string_length, optimised for sizeof(U) == sizeof(char).
|
||||
//*********************************************************************
|
||||
template <typename U>
|
||||
static
|
||||
typename etl::enable_if<sizeof(U) == sizeof(char), size_t>::type
|
||||
get_string_length(const U* src)
|
||||
{
|
||||
return ::strlen(reinterpret_cast<const char*>(src));
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// get_string_length, optimised for sizeof(U) == sizeof(wchar_t).
|
||||
//*********************************************************************
|
||||
template <typename U>
|
||||
static
|
||||
typename etl::enable_if<sizeof(U) == sizeof(wchar_t), size_t>::type
|
||||
get_string_length(const U* src)
|
||||
{
|
||||
return ::wcslen(reinterpret_cast<const wchar_t*>(src));
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// get_string_length, optimised for anything else.
|
||||
//*********************************************************************
|
||||
template <typename U>
|
||||
static
|
||||
typename etl::enable_if<(sizeof(U) != sizeof(char)) && (sizeof(U) != sizeof(wchar_t)), size_t>::type
|
||||
get_string_length(const U* src)
|
||||
{
|
||||
return etl::strlen(src);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Common implementation for 'assign' and 'append' for iterators.
|
||||
//*********************************************************************
|
||||
@ -2860,6 +2826,57 @@ namespace etl
|
||||
return size() - sz - etl::distance(rbegin(), iposition);
|
||||
}
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// get_string_length, optimised for sizeof(U) == sizeof(char).
|
||||
//*********************************************************************
|
||||
template <typename U>
|
||||
static
|
||||
typename etl::enable_if<sizeof(U) == sizeof(char), size_t>::type
|
||||
get_string_length(const U* str)
|
||||
{
|
||||
return ::strlen(reinterpret_cast<const char*>(str));
|
||||
}
|
||||
|
||||
#if ETL_USING_WIDE_CHARACTERS
|
||||
//*********************************************************************
|
||||
/// get_string_length, optimised for sizeof(U) == sizeof(wchar_t).
|
||||
//*********************************************************************
|
||||
template <typename U>
|
||||
static
|
||||
typename etl::enable_if<sizeof(U) == sizeof(wchar_t), size_t>::type
|
||||
get_string_length(const U* str)
|
||||
{
|
||||
return ::wcslen(reinterpret_cast<const wchar_t*>(str));
|
||||
}
|
||||
#endif
|
||||
|
||||
//*********************************************************************
|
||||
/// get_string_length, optimised for anything else.
|
||||
//*********************************************************************
|
||||
template <typename U>
|
||||
static
|
||||
#if ETL_USING_WIDE_CHARACTERS
|
||||
typename etl::enable_if<(sizeof(U) != sizeof(char)) && (sizeof(U) != sizeof(wchar_t)), size_t>::type
|
||||
#else
|
||||
typename etl::enable_if<(sizeof(U) != sizeof(char)), size_t>::type
|
||||
#endif
|
||||
get_string_length(const U* str)
|
||||
{
|
||||
if (str == ETL_NULLPTR)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const U* end = str;
|
||||
|
||||
while (*end++ != 0)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
return size_t(end - str) - 1;
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
@ -3117,6 +3134,8 @@ namespace etl
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef ETL_USING_WCHAR_T_H
|
||||
|
||||
#include "private/minmax_pop.h"
|
||||
|
||||
#endif
|
||||
|
||||
@ -138,6 +138,16 @@ SOFTWARE.
|
||||
#define ETL_NOT_USING_64BIT_TYPES 0
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
// For when the runtime library is compiled without wchar_t support.
|
||||
#if defined(ETL_NO_WIDE_CHARACTERS)
|
||||
#define ETL_USING_WIDE_CHARACTERS 0
|
||||
#define ETL_NOT_USING_WIDE_CHARACTERS 1
|
||||
#else
|
||||
#define ETL_USING_WIDE_CHARACTERS 1
|
||||
#define ETL_NOT_USING_WIDE_CHARACTERS 0
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
// Figure out things about the compiler, if haven't already done so in etl_profile.h
|
||||
#include "profiles/determine_compiler_version.h"
|
||||
@ -559,6 +569,7 @@ namespace etl
|
||||
static ETL_CONSTANT bool using_generic_compiler = (ETL_USING_GENERIC_COMPILER == 1);
|
||||
static ETL_CONSTANT bool using_legacy_bitset = (ETL_USING_LEGACY_BITSET == 1);
|
||||
static ETL_CONSTANT bool using_exceptions = (ETL_USING_EXCEPTIONS == 1);
|
||||
static ETL_CONSTANT bool using_wide_characters = (ETL_USING_WIDE_CHARACTERS == 1);
|
||||
|
||||
// Has...
|
||||
static ETL_CONSTANT bool has_initializer_list = (ETL_HAS_INITIALIZER_LIST == 1);
|
||||
|
||||
@ -41,6 +41,7 @@ namespace
|
||||
{
|
||||
TEST(test_traits_values)
|
||||
{
|
||||
// Using...
|
||||
CHECK_EQUAL((ETL_USING_STL == 1), etl::traits::using_stl);
|
||||
CHECK_EQUAL((ETL_USING_STLPORT == 1), etl::traits::using_stlport);
|
||||
CHECK_EQUAL((ETL_USING_CPP11 == 1), etl::traits::using_cpp11);
|
||||
@ -49,6 +50,7 @@ namespace
|
||||
CHECK_EQUAL((ETL_USING_CPP20 == 1), etl::traits::using_cpp20);
|
||||
CHECK_EQUAL((ETL_USING_CPP23 == 1), etl::traits::using_cpp23);
|
||||
CHECK_EQUAL((ETL_USING_EXCEPTIONS == 1), etl::traits::using_exceptions);
|
||||
CHECK_EQUAL((ETL_USING_WIDE_CHARACTERS == 1), etl::traits::using_wide_characters);
|
||||
CHECK_EQUAL((ETL_USING_GCC_COMPILER == 1), etl::traits::using_gcc_compiler);
|
||||
CHECK_EQUAL((ETL_USING_MICROSOFT_COMPILER == 1), etl::traits::using_microsoft_compiler);
|
||||
CHECK_EQUAL((ETL_USING_ARM5_COMPILER == 1), etl::traits::using_arm5_compiler);
|
||||
@ -60,9 +62,10 @@ namespace
|
||||
CHECK_EQUAL((ETL_USING_INTEL_COMPILER == 1), etl::traits::using_intel_compiler);
|
||||
CHECK_EQUAL((ETL_USING_TEXAS_INSTRUMENTS_COMPILER == 1), etl::traits::using_texas_instruments_compiler);
|
||||
CHECK_EQUAL((ETL_USING_GENERIC_COMPILER == 1), etl::traits::using_generic_compiler);
|
||||
|
||||
CHECK_EQUAL((ETL_USING_8BIT_TYPES == 1), etl::traits::has_8bit_types);
|
||||
CHECK_EQUAL((ETL_USING_64BIT_TYPES == 1), etl::traits::has_64bit_types);
|
||||
|
||||
// Has...
|
||||
CHECK_EQUAL((ETL_HAS_ATOMIC == 1), etl::traits::has_atomic);
|
||||
CHECK_EQUAL((ETL_HAS_MUTEX == 1), etl::traits::has_mutex);
|
||||
CHECK_EQUAL((ETL_HAS_NULLPTR == 1), etl::traits::has_nullptr);
|
||||
@ -80,7 +83,10 @@ namespace
|
||||
CHECK_EQUAL((ETL_HAS_VIRTUAL_MESSAGES == 1), etl::traits::has_virtual_messages);
|
||||
CHECK_EQUAL((ETL_HAS_PACKED == 1), etl::traits::has_packed);
|
||||
|
||||
// Is...
|
||||
CHECK_EQUAL((ETL_IS_DEBUG_BUILD == 1), etl::traits::is_debug_build);
|
||||
|
||||
// Other
|
||||
CHECK_EQUAL(__cplusplus, etl::traits::cplusplus);
|
||||
CHECK_EQUAL(ETL_VERSION_MAJOR, etl::traits::version_major);
|
||||
CHECK_EQUAL(ETL_VERSION_MINOR, etl::traits::version_minor);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user