utils.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <typeindex>
4 #include <unordered_map>
5 #include <iostream>
6 #include <optional>
7 #include <vector>
8 
9 namespace iv
10 {
11 
12 //------------------------- iterators --------------------------------
13 template< class T >
14 struct reversed
15 {
16 public:
17  reversed( T & cont ) : cont( cont ){}
18 
19  typename T::reverse_iterator begin(){ return this->cont.rbegin(); }
20  typename T::reverse_iterator end(){ return this->cont.rend(); }
21 
22 private:
23  T & cont;
24 };
25 
27 // std::unordered_map< int, Item * > m;
28 // Item * item = at_or( m, 13, nullptr );
29 // if( item )
30 // {
31 // ...
32 // }
33 //*/
34 //template< class Key, class T, class Hash, class KeyEqual, class Allocator >
35 //T const & at_or( std::unordered_map< Key, T, Hash, KeyEqual, Allocator > const & cont, Key const & key, T const & def )
36 //{
37 // auto it = cont.find( key );
38 // if( it == cont.end() )
39 // return def;
40 // else
41 // return it->second;
42 //}
43 
44 //----------------- utf8 -----------------------------------
45 size_t utf8_size( const char * );
46 size_t utf8_size( std::string const & );
47 bool utf8_is_first_byte( char );
48 
49 //------------------ string --------------------------------
50 void string_explode( std::string const & s, char delim, std::vector< std::string > & result );
51 std::string string_trim( std::string const & s );
52 std::string string_ltrim( std::string const & s );
53 std::string string_rtrim( std::string const & s );
54 
55 }