bool
stemplate <bool AllowDuplicate, bool SortElements, bool CheckOutOfRange>
struct just_another_container;
bool
, if you make a mistake on the order of arguments, you could hardly discover it before the program goes mad.Another approach is, to merge all
bool
s to a single unsigned
, liketemplate <unsigned Policy>
struct just_another_container;
enum {
ALLOW_DUP_MASK = 1,
SORT_ELE_MASK = 2,
CHECK_OUT_OF_RANGE_MASK = 4,
};
insert
interface to the container, which is concerned about whether or not allows duplicated elements in the container, the code may look likevoid insert(element_type e)
{
_insert<Policy & ALLOW_DUP_MASK>(e);
}
template <>
void _insert<0>(element_type e);
template <>
void _insert<ALLOW_DUP_MASK>(element_type e);
_insert
into a template struct
, liketemplate <unsigned AllowDuplicate>
struct insert_s
{
static void insert(just_a_container& container, element_type& e);
};
template <>
struct insert_s<ALLOW_DUP_MASK>
{
static void insert(just_a_container& container, element_type& e);
};