Skip to content

Latest commit

 

History

History
56 lines (41 loc) · 945 Bytes

036-cpp17-core-using-declaration-pack-expansion.md

File metadata and controls

56 lines (41 loc) · 945 Bytes

可変長using宣言

この機能は超上級者向けだ。

C++17ではusing宣言をカンマで区切ることができるようになった。

int x, y ;

int main()
{
    using ::x, ::y ;
}

これは、C++14で

using ::x ;
using ::y ;

と書くのと等しい。

C++17では、using宣言でパック展開ができるようになった。この機能に正式な名前はついていないが、可変長using宣言(Variadic using declaration)と呼ぶのがわかりやすい。

template < typename ... Types >
struct S : Types ...
{
    using Types::operator() ... ;
    void operator () ( long ) { }
} ;


struct A
{
    void operator () ( int ) { }
} ;

struct B
{
    void operator () ( double ) { }
} ;

int main()
{
    S<A, B> s ;
    s(0) ; // A::operator()
    s(0L) ; // S::operator()
    s(0.0) ; // B::operator()
}

機能テストマクロは__cpp_variadic_using, 値は201611。