Questions tagged [iota]

The iota function is used by several programming languages or their libraries to initialize a sequence with uniformly increasing values.

Definition:

The iota function is used by several programming languages or their libraries to initialize a sequence with uniformly increasing values.

The APL programming language uses the iota symbol () to generate sequences of successive integers.

The C++ language recently added iota to the standard library in the <numeric> header. The iota template function has existed in several unofficial C++ template libraries for years.

Important Links:

65 questions
52
votes
5 answers

Set std::vector to a range

What's the best way for setting an std::vector to a range, e.g. all numbers between 3 and 16?
Andreas
  • 7,470
  • 10
  • 51
  • 73
50
votes
4 answers

What's the full name for `iota` in golang?

As title, what's the full name for iota (not the usage) in golang: const ( // iota is reset to 0 c0 = iota // c0 == 0 c1 = iota // c1 == 1 c2 = iota // c2 == 2 )
schemacs
  • 2,783
  • 8
  • 35
  • 53
11
votes
4 answers

What would be a good implementation of iota_n (missing algorithm from the STL)

With C++11, the STL has now a std::iota function (see a reference). In contrast to std::fill_n, std::generate_n, there is no std::iota_n, however. What would be a good implementation for that? A direct loop (alternative 1) or delegation to…
TemplateRex
  • 69,038
  • 19
  • 164
  • 304
10
votes
1 answer

Why isn't std::iota constexpr?

The following program prints out a shuffled deck of cards (as integers): #include #include #include #include typedef unsigned int card; typedef std::array deck; auto shuffled_deck(){ deck d =…
Willy Goat
  • 1,175
  • 2
  • 9
  • 24
8
votes
1 answer

Implementing Iota in Haskell

Iota is a ridiculously small "programming language" using only one combinator. I'm interested in understanding how it works, but it would be helpful to see the implementation in a language I'm familiar with. I found an implementation of the Iota…
Josh Voigts
  • 4,114
  • 1
  • 18
  • 43
7
votes
2 answers

Writing powers of 10 as constants compactly

I'm reading the recently released The Go Programming Language, and it's been a joy so far (with Brian Kernighan being one of the authors, I wouldn't expect anything other than excellence anyway). I've come across the following exercise on chapter…
Filipe Gonçalves
  • 20,783
  • 6
  • 53
  • 70
6
votes
2 answers

Why didn't they add an operator version of iota?

The iota template function was added to the standard library to fill an iterator range with an increasing sequence of values. template void iota(ForwardIterator first, ForwardIterator last, Tp value) …
emsr
  • 15,539
  • 6
  • 49
  • 62
5
votes
2 answers

Using go/ast for iota declarations

I've been working with go/ast to parse go source code and copy it into another file as part of a vendoring exercise. I've got most things handled - functions, types etc - but I'm struggling with const declarations which use iota. I'm iterating…
Aditya
  • 53
  • 3
5
votes
0 answers

node.js Browserify Unexpected character '�' (1:0) while parsing /node_modules/opencv4nodejs/build/Release/opencv4nodejs.node

I was trying to use browerify and got this error I tried to typebrowserify index.js -o bundle.js and got the following error SyntaxError: Unexpected character '�' (1:0) while parsing…
matt
  • 131
  • 1
  • 8
5
votes
1 answer

How to skip a lot of values when define const variable with iota?

Say I have next c program: #include int main(int args, char* argv[]) { enum RC { APPLE=0, ORANGE, PEAR, BANANA=99, GRAPE }; printf("%d, %d, %d, %d, %d\n", APPLE, ORANGE, PEAR, BANANA,…
atline
  • 28,355
  • 16
  • 77
  • 113
5
votes
3 answers

ENUMs for custom types in GO

I am trying to generate an enum for a type I defined type FeeStage int From this I learned that I can use iota to create an enum based on this type const( Stage1 FeeStage = iota Stage2 Stage3 ) However, manipulating the actual…
Benjamin Kadish
  • 1,472
  • 11
  • 20
4
votes
1 answer

What's the exact meaning of iota?

In the code below: const ( signature uint32 = 0xae3179fb dhkxGroup = 2 ReplySuccessful byte = iota ReplyBufferCorrupted ReplyDecryptFailed ReplySessionExpired ReplyPending ) ReplySuccessful is compiled to 2, while I…
xrfang
  • 1,754
  • 4
  • 18
  • 36
4
votes
3 answers

How to use C++0x lambdas local variables for std::fill()?

So I was trying to test a lambda accessing local variables in the scope in which it is used, based roughly on a simple example by Bjarne on the C++0x FAQS page at: http://www2.research.att.com/~bs/C++0xFAQ.html#lambda When I try this simple test…
4
votes
3 answers

Why is it Called iota?

C++11 introduced a function called iota. Which "Assigns to every element in the range [first,last) successive values of val, as if incremented with ++val after each element is written." Can someone explain what "iota" means here though? I looked up…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
3
votes
1 answer

views::iota vs ranges::iota_view - "expression equivalent" so why both exist?

#include #include int main() { for (int num: std::ranges::views::iota(0,5)) { std::cout << num << 'n'; } for (int i : std::ranges::iota_view{55, 65}) { std::cout << i << '\n'; } } CPP…
Bob
  • 4,576
  • 7
  • 39
  • 107
1
2 3 4 5