1 #ifndef PYTHONIC_BUILTIN_LIST_INSERT_HPP
2 #define PYTHONIC_BUILTIN_LIST_INSERT_HPP
3 
4 #include "pythonic/include/builtins/list/insert.hpp"
5 
6 #include "pythonic/builtins/None.hpp"
7 #include "pythonic/types/list.hpp"
8 #include "pythonic/types/NoneType.hpp"
9 #include "pythonic/utils/functor.hpp"
10 
11 PYTHONIC_NS_BEGIN
12 
13 namespace builtins
14 {
15 
16   namespace list
17   {
18 
19     // TODO : range_analysis may be use to have a "fast insert" function.
20     template <class T, class F>
insert(types::list<T> & seq,long n,F && value)21     types::none_type insert(types::list<T> &seq, long n, F &&value)
22     {
23       n = n % (1 + seq.size()); // +1 because we want to be able to insert at
24                                 // the end of seq
25       if (n < 0)
26         n += seq.size();
27       seq.insert(n, std::forward<F>(value));
28       return builtins::None;
29     }
30   }
31 }
32 PYTHONIC_NS_END
33 #endif
34