1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <functional>
#include <array>
#include <map>
enum op { toPrint /* ... */ };
void print( op, int) { /* ... */ }
void print( op, int,int) { /* ... */ }
void print( op, int,int,int) { /* ... */ }
void foo( std::array<int,4> storeArguments )
{
static const std::map< std::array<int,4>, std::function< void() > > functions
{
{ { 1, 0, 0, 0 }, []() { print( toPrint, 1 ); } },
{ { 0, 2, 0, 0 }, []() { print( toPrint, 2 ); } },
{ { 1, 2, 0, 0 }, []() { print( toPrint, 1, 2 ); } },
{ { 0, 0, 4, 0 }, []() { print( toPrint, 4 ); } },
{ { 1, 2, 4, 0 }, []() { print( toPrint, 1, 2, 4 ); } },
{ { 1, 0, 0, 8 }, []() { print( toPrint, 1, 8 ); } }
// etc.
};
auto iter = functions.find( storeArguments ) ;
if( iter != functions.end() ) iter->second() ;
}
|