summaryrefslogtreecommitdiff
path: root/src/examples/eina_cxx/eina_cxx_list_01.cc
blob: f74f9d644a753f6044e49d27af000e183d6fb9cc (plain) (blame)
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
51
52
53
54
55
56
57
58
59
60
//Compile with:
//gcc -g eina_list_01.c -o eina_list_01 `pkg-config --cflags --libs eina`

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdio.h>
#include <Eina.hh>

#include <iterator>
#include <algorithm>

#include <iostream>

template <typename I>
I next(I i, std::size_t n = 1u)
{
  for(;n;--n)
    ++i;
  return i;
}

int main()
{
   efl::eina::eina_init eina_init;

   efl::eina::ptr_list<std::string, efl::eina::heap_copy_allocator> list;

   list.push_back("tigh");
   list.push_back("adar");
   list.push_back("baltar");
   list.push_back("roslin");

   for(efl::eina::ptr_list<std::string>::const_iterator
         first = list.begin(), last = list.end()
         ;first != last; ++first)
     std::cout << *first << std::endl;

   efl::eina::ptr_list<std::string>::iterator
     iterator = ::next(list.begin(), 2u);
   list.insert(iterator, "cain");

   iterator = std::find(list.begin(), list.end(), "cain");
   assert(iterator != list.end() && ::next(iterator) != list.end());
   list.insert(::next(iterator), "zarek");

   list.insert(list.begin(), "adama");

   iterator = std::find(list.begin(), list.end(), "cain");
   assert(iterator != list.end());
   list.insert(iterator, "gaeta");

   list.insert(::next(list.begin()), "lampkin");

   for(efl::eina::ptr_list<std::string>::const_iterator
         first = list.begin(), last = list.end()
         ;first != last; ++first)
     std::cout << *first << std::endl;
}