I
Immortal Nephi
How do you create template array at compile-time? I pulled
information from http://www.parashift.com/c++-faq-lite/pointers-to-members.html
and the question is “[33.14] Can you make functionoids faster than
normal function calls?”
Notice blah function. Can you create functObj array in blah function
at compile-time?
class Funct1 {
public:
Funct1(float y) : y_(y) { }
int operator()(int x) { ...code from funct1... }
private:
float y_;
};
class Funct2 {
public:
Funct2(std::string const& y, int z) : y_(y), z_(z) { }
int operator()(int x) { ...code from funct2... }
private:
std::string y_;
int z_;
};
class Funct3 {
public:
Funct3(const std::vector<double>& y) : y_(y) { }
int operator()(int x) { ...code from funct3... }
private:
std::vector<double> y_;
};
template <typename FunctObj>
void myCode(FunctObj f)
{
// ...
f(...args-go-here...);
// ...
}
void blah()
{
// ...
Funct2 x("functionoids are powerful", 42);
myCode(x);
// ...
}
information from http://www.parashift.com/c++-faq-lite/pointers-to-members.html
and the question is “[33.14] Can you make functionoids faster than
normal function calls?”
Notice blah function. Can you create functObj array in blah function
at compile-time?
class Funct1 {
public:
Funct1(float y) : y_(y) { }
int operator()(int x) { ...code from funct1... }
private:
float y_;
};
class Funct2 {
public:
Funct2(std::string const& y, int z) : y_(y), z_(z) { }
int operator()(int x) { ...code from funct2... }
private:
std::string y_;
int z_;
};
class Funct3 {
public:
Funct3(const std::vector<double>& y) : y_(y) { }
int operator()(int x) { ...code from funct3... }
private:
std::vector<double> y_;
};
template <typename FunctObj>
void myCode(FunctObj f)
{
// ...
f(...args-go-here...);
// ...
}
void blah()
{
// ...
Funct2 x("functionoids are powerful", 42);
myCode(x);
// ...
}