Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
38 lines (25 sloc) 1.11 KB

dependent_false

Source code

A static_assert helper.

.. struct:: template<class T> tl::dependent_false : std::false_type

    Always false, but dependent on a template parameter, so can be used
    in `static_asserts` which you want to always fail.

    Example: ::

        template <class T> void f(std::vector<T>){
            // ...
        }

        template <class T> void f(T) {
            static_assert(false, "T must be a specialization of std::vector");
        }

    The above code is ill-formed, no diagnostic required due to
    `[temp.res]/8.1 <http://eel.is/c++draft/temp#res-8.1>`_:

        The program is ill-formed, no diagnostic required, if:

        - no valid specialization can be generated for a template [...]

    One can get around this using `dependent_false`: ::

        template <class T> void f(std::vector<T>){
            // ...
        }

        template <class T> void f(T) {
            static_assert(tl::dependent_false<T>::value, "T must be a specialization of std::vector");
        }
You can’t perform that action at this time.