I ran into a compatiblity issue between etl and the standard library when working with strings. My existing code uses std::string_view (instead of etl::string_view). It appears that ETL has no conversion between the two types so I cannot, for example, do the following:
etl::string<64> myString;
std::string_view myStringView; //Assume this is provided somewhere else
myString += myStringView;
I noticed the following preprocessor test in string_view.h:
#if ETL_USING_STL && ETL_USING_CPP17
#include <string_view>
#endif
But, other than include std::string_view, it doesn't seem to do anything with it.
My solution was to make the following changes:
In string_view.h
Wrap the basic_string_view class in a preprocessor check that simply causes etl::basic_string_view to std::basic_string_view
#if ETL_USING_STL && ETL_USING_CPP17
template <typename T, typename TTraits = std::char_traits<T> >
using basic_string_view = std::basic_string_view<T, TTraits>;
#else
template <typename T, typename TTraits = etl::char_traits<T> >
class basic_string_view
{
//EXISTING CODE...
In basic_string.h
Add an implicit conversion operator in ibasic_string to etl::basic_string_view
template <typename T>
class ibasic_string : public::string_base
{
//EXISTING CODE...
//*************************************************************************
/// Conversion operator to etl::basic_string_view.
//*************************************************************************
operator etl::basic_string_view<T>() const
{
return etl::basic_string_view<T>(p_buffer, size());
}
That way, if std::string_view is available, ETL just uses it directly.
The other option I can think of would be to explicitly add conversion operators and constructors for std::string_view (along with etl::string_view) to etl::ibasic_string.
I ran into a compatiblity issue between etl and the standard library when working with strings. My existing code uses
std::string_view(instead ofetl::string_view). It appears that ETL has no conversion between the two types so I cannot, for example, do the following:I noticed the following preprocessor test in string_view.h:
But, other than include
std::string_view, it doesn't seem to do anything with it.My solution was to make the following changes:
In string_view.h
Wrap the basic_string_view class in a preprocessor check that simply causes
etl::basic_string_viewtostd::basic_string_viewIn basic_string.h
Add an implicit conversion operator in
ibasic_stringtoetl::basic_string_viewThat way, if
std::string_viewis available, ETL just uses it directly.The other option I can think of would be to explicitly add conversion operators and constructors for
std::string_view(along withetl::string_view) toetl::ibasic_string.