added std::string conversion for fc::string

This commit is contained in:
Daniel Larimer 2012-10-09 23:21:41 -04:00
parent 3f73d25e44
commit c174a93ffb
2 changed files with 38 additions and 0 deletions

View file

@ -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();

View file

@ -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 );