summaryrefslogtreecommitdiff
path: root/src/examples/eina_cxx/eina_cxx_list_01.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/eina_cxx/eina_cxx_list_01.cc')
-rw-r--r--src/examples/eina_cxx/eina_cxx_list_01.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/examples/eina_cxx/eina_cxx_list_01.cc b/src/examples/eina_cxx/eina_cxx_list_01.cc
new file mode 100644
index 0000000000..b451ef1553
--- /dev/null
+++ b/src/examples/eina_cxx/eina_cxx_list_01.cc
@@ -0,0 +1,55 @@
1//Compile with:
2//gcc -g eina_list_01.c -o eina_list_01 `pkg-config --cflags --libs eina`
3
4#include <stdio.h>
5#include <Eina.hh>
6
7#include <iterator>
8#include <algorithm>
9
10#include <iostream>
11
12template <typename I>
13I next(I i, std::size_t n = 1u)
14{
15 for(;n;--n)
16 ++i;
17}
18
19int main(int argc, char **argv)
20{
21 efl::eina::eina_init eina_init;
22
23 efl::eina::ptr_list<std::string, efl::eina::heap_copy_allocator> list;
24
25 list.push_back("tigh");
26 list.push_back("adar");
27 list.push_back("baltar");
28 list.push_back("roslin");
29
30 for(efl::eina::ptr_list<std::string>::const_iterator
31 first = list.begin(), last = list.end()
32 ;first != last; ++first)
33 std::cout << *first << std::endl;
34
35 efl::eina::ptr_list<std::string>::iterator
36 iterator = ::next(list.begin(), 2u);
37 list.insert(iterator, "cain");
38
39 iterator = std::find(list.begin(), list.end(), "cain");
40 assert(iterator != list.end() && ::next(iterator) != list.end());
41 list.insert(::next(iterator), "zarek");
42
43 list.insert(list.begin(), "adama");
44
45 iterator = std::find(list.begin(), list.end(), "cain");
46 assert(iterator != list.end());
47 list.insert(iterator, "gaeta");
48
49 list.insert(::next(list.begin()), "lampkin");
50
51 for(efl::eina::ptr_list<std::string>::const_iterator
52 first = list.begin(), last = list.end()
53 ;first != last; ++first)
54 std::cout << *first << std::endl;
55}