added std::string conversion for fc::string
This commit is contained in:
parent
3f73d25e44
commit
c174a93ffb
2 changed files with 38 additions and 0 deletions
|
|
@ -2,6 +2,25 @@
|
|||
#define _FC_STRING_HPP_
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
/**
|
||||
* There is debate about whether doing this is 'standard conforming', but
|
||||
* it works everywhere and enables the purpose of this library which is to
|
||||
* accelerate compiles while maintaining compatability.
|
||||
*/
|
||||
namespace std {
|
||||
template<class Char>
|
||||
struct char_traits;
|
||||
|
||||
template<class T>
|
||||
struct allocator;
|
||||
|
||||
template<class Char, class Traits, class Allocator>
|
||||
struct basic_string;
|
||||
|
||||
typedef basic_string<char, char_traits<char>, allocator<char> > string;
|
||||
}
|
||||
|
||||
namespace fc {
|
||||
/**
|
||||
* Including <string> results in 4000 lines of code
|
||||
|
|
@ -17,6 +36,8 @@ namespace fc {
|
|||
typedef const char* const_iterator;
|
||||
|
||||
string();
|
||||
string( const std::string& s );
|
||||
string( std::string&& s );
|
||||
string( const string& c );
|
||||
string( string&& c );
|
||||
string( const char* c );
|
||||
|
|
@ -24,6 +45,9 @@ namespace fc {
|
|||
string( const_iterator b, const_iterator e );
|
||||
~string();
|
||||
|
||||
operator std::string&();
|
||||
operator const std::string&()const;
|
||||
|
||||
iterator begin();
|
||||
iterator end();
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,21 @@ namespace fc {
|
|||
static_assert( sizeof(my) >= sizeof(std::string), "failed to reserve enough space" );
|
||||
new (this) std::string(b,e);
|
||||
}
|
||||
string::string( const std::string& s ) {
|
||||
static_assert( sizeof(my) >= sizeof(std::string), "failed to reserve enough space" );
|
||||
new (this) std::string(s);
|
||||
}
|
||||
string::string( std::string&& s ) {
|
||||
static_assert( sizeof(my) >= sizeof(std::string), "failed to reserve enough space" );
|
||||
new (this) std::string(fc::move(s));
|
||||
}
|
||||
|
||||
string::operator std::string&() {
|
||||
return *reinterpret_cast<std::string*>(this);
|
||||
}
|
||||
string::operator const std::string&()const {
|
||||
return *reinterpret_cast<const std::string*>(this);
|
||||
}
|
||||
|
||||
string::~string() {
|
||||
::detail::destroy( this );
|
||||
|
|
|
|||
Loading…
Reference in a new issue