Forward declaring standard library classes
Theodore Papadopoulo
Theodore.Papadopoulo@sophia.inria.fr
Fri Nov 19 09:51:00 GMT 2004
Are you allowing yourself to modify slightly (with no user visible
change, but the ABI should be checked...) the classes vector, list, etc...
If yes, what you can do is:
Create or better reuse two types (true_type, false_type). If I
remember correctly those already exist. Alternatinvely, you might use
static const bool private members.
In each container add a :
typedef {true_type,false_type} swappable;
preferably as private and a friend declaration for your _UseSwap.
Also, you would have to forward declare _UseSwap or include it.
Then define you _UseSwap as:
template<typename _Tp>
struct _UseSwap {
{enum{_M_type = SOMETHING(_Tp::swappable)};};
};
The SOMETHING is either accessing some field of true_type, false_type
(eg a static const member) or involving some template specialized to
give the proper value :
template <typename> struct _One_For_True { };
template <> struct _One_For_True<true_type> { {enum{_M_type = 1}; };
template <> struct _One_For_True<false_type> { {enum{_M_type = 0}; };
Alternatinvely, you might use static const bool private members (so
no need for types, you directly define:
static const bool swappable = {true,false};
The friend stuff remains the same.
template<typename _Tp>
struct _UseSwap {
{enum{_M_type = _Tp::swappable ? 1 : 0; };};
Theo.
--------------------------------------------------------------------
Theodore Papadopoulo
Email: Theodore.Papadopoulo@sophia.inria.fr Tel: (33) 04 92 38 76 01
--------------------------------------------------------------------
More information about the Libstdc++
mailing list