FBB::TypeTrait

libbobcat1-dev_2.18.00-x.tar.gz

2005-2011


FBB::TypeTrait(3bobcat)

FBB::TypeTrait(3bobcat)

libbobcat1-dev_2.18.00-x.tar.gz Error handler

2005-2011

NAME

FBB::TypeTrait - shortdesc

SYNOPSIS

#include <bobcat/typetrait>

DESCRIPTION

FBB::TypeTrait is a traits class. It does not define any member functions or data members, but merely types. It can be used to determine the basic type and other characteristics of (const) plain, (const) pointer or (const) reference types. It is used, e.g., by the FBB::FnWrap* family of template classes and was designed after Alexandrescu's (2001) TypeTraits template class.

The FBB::IfElse class template allows the conditional (on a bool value) use of one of two types.

The FBB::LpromotesR class template is used to determine, compile-time, whether its second (right-hand side) template type can be promoted to its first (left-hand side) template type.

NAMESPACE

FBB
All constructors, members, operators and manipulators, mentioned in this man-page, are defined in the namespace FBB.

INHERITS FROM

-

TypeTrait<TYPE>

TYPE is the template type parameter whose characteristics must be determined.

TypeTrait<TYPE> defines the type Plain: the plain type (the type without const, pointer, reference type indication) of any const or non-const plain, pointer, lvalue- or rvalue-reference type.

TypeTrait<TYPE> defines the following bool values:

IfElse<bool, TrueType, FalseType>

IfElse<bool, TrueType, FalseType> defines the type type equal to TrueType if its bool template non-type parameter is true, and equal to FalseType if its its bool template non-type parameter is false.

LpromotesR<LeftType, RightType>

LpromotesR<LeftType, RightType> defines the enum constant yes as 1 if an RightType argument can be promoted to LeftType value or object. The enum value yes is defined as 0 if no such constructor is available or if such a constructor is defined using the explicit keyword.

EXAMPLES

The following example shows a fragment of the code used in the FBB::FnWrap1 class determining the basic type of its Type template parameter:


    #include <bobcat/typetrait>
    ...
    template <typename Type, typename ReturnType = void>
    class FnWrap1
    {
        ...
        public:
            typedef typename TypeTrait<Type>::Plain  argument_type;
        ...
    };
        
The above code could have used TypeTrait<Type>::isPointer to determine whether Type actually represents a pointer type.

Here is an example using IfElse:


    int main()
    {
        IfElse<true,  int, double>::type isInt;      
        IfElse<false, int, double>::type isDouble;      
    }
        

And an example using LpromotesR:


    int main()
    {
        cout << "string promotes char const *: " << 
                LpromotesR<string, char const *>::yes << '\n';  // 1
        cout << "string promotes string " << 
                LpromotesR<string, string>::yes << '\n';        // 1
        cout << "char const * promotes string " << 
                LpromotesR<char const *, string>::yes << '\n';  // 0
    }
        

FILES

bobcat/typetrait - defines the class interface

SEE ALSO

bobcat(7)
Alexandrescu A. (2001) Modern C++ Design, Addison-Wesley, Boston.

BUGS

None Reported.

DISTRIBUTION FILES

BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.

COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).