Name: Anonymous 2010-07-19 22:24
What does /prog/ like better?
I personally like string
I personally like string
class string_encoding; // ascii
class wstring_encoding; // wchar_t
class u8string_encoding; // utf8
class u16string_encoding; // utf16
class u32string_encoding; // utf32
template< class Encoding, class Allocator >
class generic_string;
template< class Encoding, class Container >
class generic_string_builder;
typedef generic_string<string_encoding, allocator> string;
typedef generic_string<wstring_encoding, allocator> wstring;
typedef generic_string<u8string_encoding, allocator> u8string;
typedef generic_string<u16string_encoding, allocator> u16string;
typedef generic_string<u32string_encoding, allocator> u32string;
// etc.>> part of C++ is>> these things >>
do_stuff(some_object, 1, 2, 3) significantly different than some_object.do_stuff(1, 2, 3)? You might as well use C and accomplish all the same things with less work.
typedef struct parent {
int a, b, c; /* some stuff */
} parent;
typedef struct child {
parent p;
int d, e;
} child;
/* ... */
#define PARENT(obj) ((parent *) (obj))
#define parent_do_stuff(obj, a, b, c) _parent_do_stuff(PARENT(obj), a, b, c)child *c = new_child();
parent_do_stuff(c, 1, 2, 3);int rtti in your parent object and contrive some sort of isa() to verify that the pointed object is of the appropriate type.
this is a keyword, and classes, objects and operator overloading aren't just syntactic sugar.
class allocator
{
static bool const is_thread_safe = true;
/* ... */
};
enum memory_order
{
memory_order_relaxed,
memory_order_consume,
memory_order_acquire,
memory_order_release,
memory_order_acq_rel,
memory_order_seq_cst
}
template< typename T >
class atomic
{
inline void add< memory_order >(T value) {
// magic
}
};
template< class Encoding, class Allocator >
{
private:
// intrusive reference counted instance
struct instance
{
atomic< int32_t > use_count;
typename Encoding::size_type size;
typename Encoding::char_type data[];
};
void acquire() {
instance_->use_count.add< Allocator::is_thread_safe ? memory_order_consume : memory_order_relaxed >(1);
}
};