C++, repeat an input for a function multiple times

M.Mac

Is it possible to create an input, which is than repeated N times as a parameter for the function?

An example:

#include <range/v3/view/indices.hpp>
#include <range/v3/view/cartesian_product.hpp>

template<std::size_t length, std::size_t N>
constexpr auto tensor_cartesian_product(){

    const auto cart_input1 = ranges::view::indices(length); //create input

    return ranges::view::cartesian_product(cart_input1, cart_input1, ... /* N times cart_input1 */);
}
Evg

You can use pack expansion:

template<std::size_t length, std::size_t... is>
constexpr auto tensor_cartesian_product(std::index_sequence<is...>) {
    const auto cart_input = ranges::view::indices(length);
    return ranges::view::cartesian_product((is, cart_input)...);
}

template<std::size_t length, std::size_t N>
constexpr auto tensor_cartesian_product() {
    return tensor_cartesian_product<length>(std::make_index_sequence<N>{});
}

The trick here is to harness the comma operator:

The comma operator expressions have the form: E1 , E2.

In a comma expression E1, E2, the expression E1 is evaluated, its result is discarded ... . The type, value, and value category of the result of the comma expression are exactly the type, value, and value category of the second operand, E2. ...

The pack (is, cart_input)... will be expanded into (0, cart_input), (1, cart_input), ..., (N - 1, cart_input), and the result of evaluation of each of N terms will be cart_input.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

ng-change function called multiple times from input inside ng-repeat

From Dev

Need button to repeat the same function multiple times

From Dev

Function to repeat a range of cells multiple times in a column

From Dev

Why does this python comprehension repeat the user input multiple times?

From Dev

Testing a Function by Passing Input Multiple Times

From Dev

Avoid evaluating the function with same input multiple times

From Dev

Passing the output of a function back to the input multiple times

From Dev

jquery on change and input function run multiple times

From Dev

Repeat same JS function multiple times on same page

From Dev

How do i repeat my function multiple times with updated values?

From Dev

Repeat a function 1000 times

From Dev

Repeat a function 3 times

From Dev

Reading the same input multiple times - C

From Dev

In C, why does detecting char input from a recursive function cause it to run multiple times more than necessary?

From Dev

Repeat R script multiple times

From Dev

Repeat each line multiple times

From Dev

How to repeat Await multiple times?

From Dev

Angular @Input binding using function calling multiple times

From Dev

Why is Angular input [value] = "function()" running multiple times?

From Dev

for/if loop to run a function multiple times depending on input :: jquery

From Dev

Read input multiple times

From Dev

Repeat a function N times in Scala

From Dev

How to repeat a function five times?

From Dev

Repeat a function 5 times with for on JavaScript

From Dev

How to store the output of a function and take the stored output as the next input and repeat this process a specific number of times

From Dev

How to run a c++ program multiple times with different input files?

From Dev

C++ Do-While loop not accepting input multiple times

From Dev

C++ use function's output as functions input n times

From Dev

How to repeat a geospatial function multiple times, insert the results into a new column using data from the same and upcoming row

Related Related

  1. 1

    ng-change function called multiple times from input inside ng-repeat

  2. 2

    Need button to repeat the same function multiple times

  3. 3

    Function to repeat a range of cells multiple times in a column

  4. 4

    Why does this python comprehension repeat the user input multiple times?

  5. 5

    Testing a Function by Passing Input Multiple Times

  6. 6

    Avoid evaluating the function with same input multiple times

  7. 7

    Passing the output of a function back to the input multiple times

  8. 8

    jquery on change and input function run multiple times

  9. 9

    Repeat same JS function multiple times on same page

  10. 10

    How do i repeat my function multiple times with updated values?

  11. 11

    Repeat a function 1000 times

  12. 12

    Repeat a function 3 times

  13. 13

    Reading the same input multiple times - C

  14. 14

    In C, why does detecting char input from a recursive function cause it to run multiple times more than necessary?

  15. 15

    Repeat R script multiple times

  16. 16

    Repeat each line multiple times

  17. 17

    How to repeat Await multiple times?

  18. 18

    Angular @Input binding using function calling multiple times

  19. 19

    Why is Angular input [value] = "function()" running multiple times?

  20. 20

    for/if loop to run a function multiple times depending on input :: jquery

  21. 21

    Read input multiple times

  22. 22

    Repeat a function N times in Scala

  23. 23

    How to repeat a function five times?

  24. 24

    Repeat a function 5 times with for on JavaScript

  25. 25

    How to store the output of a function and take the stored output as the next input and repeat this process a specific number of times

  26. 26

    How to run a c++ program multiple times with different input files?

  27. 27

    C++ Do-While loop not accepting input multiple times

  28. 28

    C++ use function's output as functions input n times

  29. 29

    How to repeat a geospatial function multiple times, insert the results into a new column using data from the same and upcoming row

HotTag

Archive