Default function that just returns the passed value?

前端 未结 6 1514
礼貌的吻别
礼貌的吻别 2020-12-31 08:24

As a lazy developer, I like to use this trick to specify a default function:

template 

        
6条回答
  •  清酒与你
    2020-12-31 09:14

    boost::phoenix offers a complete functional toolbox, here 'arg1' is the ident to identity ;-)

    #include 
    
    template 
    void index(X &x, Function f = Function()) {
        for (std::size_t i = 0; i < x.size(); ++i) {
                x[i] = f(i);
      }
    }
    

提交回复
热议问题