Section 2.8.  History
Team LiB
Previous Section Next Section

2.8. History

The Boost Type Traits library was inspired by a component in SGI's STL implementation that looked something like this:



    struct true_type {}; struct false_type {};





    template <class T> struct type_traits // assume nothing


    {


       typedef false_type has_trivial_default_constructor;


       typedef false_type has_trivial_copy_constructor;


       typedef false_type has_trivial_assignment_operator;


       typedef false_type has_trivial_destructor;


       typedef false_type is_POD_type;


    };





    template<> struct type_traits<char> // specialization for char


    {


       typedef true_type has_trivial_default_constructor;


       typedef true_type has_trivial_copy_constructor;


       typedef true_type has_trivial_assignment_operator;


       typedef true_type has_trivial_destructor;


       typedef true_type is_POD_type;


    };


    more specializations follow...



It's interesting to note that although the SGI type traits yielded result types, it's still a "blob," which kills polymorphism. The SGI designers must have had other reasons for using nested types instead of bool constants.[10]

[10] For a clue as to one possible reason, see section 9.2.3.

Boost. Type Traits was the first C++ library that explicitly recognized the importance of using single-valued metafunctions. Boost rejected the "blob" design primarily because it would reserve a very general name, type_traits, for a single template. The name seemed to demand that any new traits be assimilated therea Borg blob! Anyone who wanted to write a similar component would have felt compelled to go in and modify this one template, potentially causing bugs. At the time, the positive impact this choice would have on efficiency and interoperability wasn't well understood.

The designers established a convention that traits with a Boolean result would have a ::value and those with a type result would have a ::type, so users didn't have to guess at how to invoke a given trait. That choice indicates that they recognized the value of polymorphism, even if they didn't reach the ultimate conclusion that all metafunctions should supply a ::type.

As a matter of fact, the type traits weren't seen as "metafunctions" until work on the Boost Metaprogramming Library (MPL) was begun. At that point, the convention used in the Type Traits library became the basis for the uniform protocol used by MPL metafunctions, and Boost Type Traits library was updated accordingly.

    Team LiB
    Previous Section Next Section