-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreation.cpp
More file actions
50 lines (38 loc) · 1.25 KB
/
creation.cpp
File metadata and controls
50 lines (38 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// This example demonstrates the various ways to create sequences
#include <sequence.hpp>
#include <iostream>
#include <vector>
#include <sstream>
void print(const sequence<const char*> & items)
{
for(auto i : items)
std::cout << i << std::endl;
}
int main()
{
// Create an empty sequence (or an empty list - they are the same thing)
print(seq<const char*>());
print(list<const char*>());
// Create a sequence with the given items
print(list("hello"));
print(list("cat", "dog", "parrot"));
// Create a sequence from a container
std::vector<const char*> items { "Beethoven", "Chopin", "Liszt"};
print(seq(items));
// Create a sequence from iterators
print(seq(items.rbegin(), items.rend()));
// Create a sequence from C arrays
const char *carray[] = { "Red", "White", "Rose" };
print(seq(carray));
print(seq(carray+1, 2));
// Create an integer range
auto r = seq(1,10);
// Output: 55
std::cout << r.sum() << std::endl;
// Create a sequence of characters in a C string
std::cout << seq("Bergerac").size() << std::endl;
// Create a sequence of characters from a stream
std::stringstream ss("a b c");
std::cout << seq(ss).front() << std::endl;
return 0;
}