Search Results

Search found 2 results on 1 pages for 'kirakun'.

Page 1/1 | 1 

  • C++ Iterator Pipelining Designs

    - by Kirakun
    Suppose we want to apply a series of transformations, int f1(int), int f2(int), int f3(int), to a list of objects. A naive way would be SourceContainer source; TempContainer1 temp1; transform(source.begin(), source.end(), back_inserter(temp1), f1); TempContainer2 temp2; transform(temp1.begin(), temp1.end(), back_inserter(temp2), f2); TargetContainer target; transform(temp2.begin(), temp2.end(), back_inserter(target), f3); This first solution is not optimal because of the extra space requirement with temp1 and temp2. So, let's get smarter with this: int f123(int n) { return f3(f2(f1(n))); } ... SourceContainer source; TargetContainer target; transform(source.begin(), source.end(), back_inserter(target), f123); This second solution is much better because not only the code is simpler but more importantly there is less space requirement without the intermediate calculations. However, the composition f123 must be determined at compile time and thus is fixed at run time. How would I try to do this efficiently if the composition is to be determined at run time? For example, if this code was in a RPC service and the actual composition--which can be any permutation of f1, f2, and f3--is based on arguments from the RPC call.

    Read the article

  • C++ Types Impossible to Name

    - by Kirakun
    While reading Wikipedia's page on decltype, I was curious about the statement, Its [decltype's] primary intended use is in generic programming, where it is often difficult, or even impossible, to name types that depend on template parameters. While I can understand the difficulty part of that statement, what is an example where there is a need to name a type that cannot be named under C++03? EDIT: My point is that since everything in C++ has a declaration of types. Why would there ever be a case where it is impossible to name a type? Furthermore, aren't trait classes designed to yield type informations? Could trait classes be an alternative to decltype?

    Read the article

1