# Group Switch Metafunction Types
Tags for the metafunction Switch and the metafunction itself.

## Grouped Tags Overview

- `struct NilCase {};`
  Tag for terminating the case in Switch statement.

## Grouped Metafunction Overview

- `template <int TAG, typename TResult, typename TNext> struct Case;`
  Tag for one case.
- `Switch<TAG, TCase>::Type`
  Switch statement for metaprogramming.

## Detailed Description

### Example

The following shows a complete example of using the Switch statement.

    int switchTest(Nothing const &)
    {
        return -1;
    }

    int switchTest(False const &)
    {
        return 0;
    }

    int switchTest(True const &)
    {
        return 1;
    }

    int switchTest(NilCase const &)
    {
        return 2;
    }

    template <int X>
    struct SwitchTest
    {
        typedef typename Switch<
            X,
            Case<-1, Nothing,
                 Case<0, False,
                      Case<1, True
                           > > > >::Type Type;
    };

    int main()
    {
        typedef SwitchTest<-1>::Type T1;
        typedef SwitchTest<0>::Type T2;
        typedef SwitchTest<1>::Type T3;
        typedef SwitchTest<2>::Type T4;

        std::cout << switchTest(T1()) << "\n"   // => "-1"
                  << switchTest(T2()) << "\n"   // => "0"
                  << switchTest(T3()) << "\n"   // => "1"
                  << switchTest(T4()) << "\n";  // => "2"

        return 0;
    }

Snippet from: demos/dox/basic/metaprogramming_switch.cpp

## Grouped Tags Detail

### `struct NilCase {};`

Tag for terminating the case in Switch statement.

## Grouped Metafunctions Detail

### `template <int TAG, typename TResult, typename TNext> struct Case;`

Tag for one case.

#### Template Parameters

`TAG` | The `int` tag number to use.
`TResult` | The type to return in `Case<...>::Type` if matches.
`TNext` | The next `Case`.

### `Switch<TAG, TCase>::Type`

Switch statement for metaprogramming.

#### Template Parameters

`TAG` | `int` with the current value.
`TCase` | First `Case` statement.

#### Returns

`Type` | The selected type.

#### Dox Sources

    /*!
     * @defgroup MetafunctionSwitch Switch Metafunction Types
     *
     * @brief Tags for the metafunction Switch and the metafunction itself.
     *
     * @section Example
     *
     * The following shows a complete example of using the Switch statement.
     *
     * @snippet demos/dox/basic/metaprogramming_switch.cpp switch demo
     *
     *
     *
     * @mfn MetafunctionSwitch#Case
     *
     * @brief Tag for one case.
     *
     * @signature template <int TAG, typename TResult, typename TNext> struct Case;
     *
     * @tparam TAG The <tt>int</tt> tag number to use.
     * @tparam TResult The type to return in <tt>Case<...>::Type</tt> if matches.
     * @tparam TNext The next <tt>Case</tt>.
     *
     * @mfn MetafunctionSwitch#Switch
     *
     * @brief Switch statement for metaprogramming.
     *
     * @signature Switch<TAG, TCase>::Type
     *
     * @tparam TAG <tt>int</tt> with the current value.
     * @tparam TCase First <tt>Case</tt> statement.
     *
     * @return Type The selected type.
     *
     * @tag MetafunctionSwitch#NilCase
     *
     * @brief Tag for terminating the case in Switch statement.
     *
     * @signature struct NilCase {};
     */