xerus
a general purpose tensor library
internal.h
Go to the documentation of this file.
1 // Xerus - A General Purpose Tensor Library
2 // Copyright (C) 2014-2017 Benjamin Huber and Sebastian Wolf.
3 //
4 // Xerus is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as published
6 // by the Free Software Foundation, either version 3 of the License,
7 // or (at your option) any later version.
8 //
9 // Xerus is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
13 //
14 // You should have received a copy of the GNU Affero General Public License
15 // along with Xerus. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // For further information on Xerus visit https://libXerus.org
18 // or contact us at contact@libXerus.org.
19 
27 #pragma once
28 #include "containerOutput.h"
29 #include <type_traits>
30 #include <memory>
31 
32 // macro shorthands
33 #define REQUIRE XERUS_REQUIRE
34 #define CHECK XERUS_CHECK
35 #define IF_CHECK XERUS_IF_CHECK
36 #define IF_NO_CHECK XERUS_IF_NO_CHECK
37 #define INTERNAL_CHECK XERUS_INTERNAL_CHECK
38 #define LOG XERUS_LOG
39 #define LOG_SHORT XERUS_LOG_SHORT
40 #define LOG_ONCE XERUS_LOG_ONCE
41 #define IS_LOGGING XERUS_IS_LOGGING
42 #define SET_LOGGING XERUS_SET_LOGGING
43 
44 
45 
46 namespace std {
47 #if !defined(__cplusplus) || __cplusplus < 201402L
48  template<typename T, typename... Args>
49  std::unique_ptr<T> make_unique(Args&&... args) {
50  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
51  }
52 #endif
53 
54 
55  using ::xerus::misc::operator<<; // for std::ostream << std::vector etc.
56 
57  //TODO No good solution, as this requires the use of std::advance, which may be less efficient than the +operator for random access iterators. (Need concepts)
59  template<class IteratorType,
60  typename std::enable_if<
61  std::is_same<typename std::iterator_traits<IteratorType>::difference_type, long>::value
62  && std::is_class<IteratorType>::value
63  , bool>::type = true>
64  IteratorType operator+(const IteratorType& _iterator, const size_t _add) {
65  IteratorType itr = _iterator;
66  std::advance(itr, _add);
67  return itr;
68  }
69 
70 
72  template<template<class, class...> class container_t, class item_t, class... rest_t>
73  container_t<item_t, rest_t...> operator |(const container_t<item_t, rest_t...> & _left, const container_t<item_t, rest_t...> & _right) {
74  container_t<item_t, rest_t...> both(_left);
75  both.insert(both.end(), _right.begin(), _right.end());
76  return both;
77  }
78 }
STL namespace.
Header file for the standard container to standard ostream operators.
std::unique_ptr< T > make_unique(Args &&... args)
Definition: internal.h:49