Skip to content

gununu/static_if

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

###STATIC_IF library for C++14 (g++ 5.1.0 or clang++ 3.4.0) Build Status

copyright 2011-2015 (c) gununu

###Lisence
Use, modification, and distribution is subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

###Usage Start with STATIC_IF and finish with STATIC_ENDIF. LAZY_VALUE and LAZY_TYPE are needed to get they dependent name.

Can't use following statement in block. "return", "break", "continue" and "goto"

###Example

template <int Val>
struct S {
    static_assert(Val < 10, "");
};

void func() {
    int a;
    const int N = 30; 
    STATIC_IF( N < 10 ) {     // (REQUIRED) if block
        S<LAZY_VALUE(N)> v;   // (REQUIRED) LAZY_VALUE or LAZY_TYPE are needed to avoid S's static_assert on clang.
        v.foobar();
        N;                    // Note: g++ 4.9.2 can't use const local variables.
    } STATIC_ELSEIF( N==10 ) { //(optional) elseif block

        STATIC_IF(true){      // (optional) nested if block
            cout << "foo";
        }STATIC_ENDIF   

    } STATIC_ELSEIF( N==20 ) { // (optional) can use elseif as many times

        cout << a;            // can use local variable

    } STATIC_ELSE {           // (optional) else block

    } STATIC_ENDIF            // (REQUIRED) end block
}

About

STATIC_IF library for C++14

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published