tatami
C++ API for different matrix representations
Loading...
Searching...
No Matches
Index_to_container.hpp
1#ifndef TATAMI_INDEX_TO_CONTAINER_HPP
2#define TATAMI_INDEX_TO_CONTAINER_HPP
3
4#include <type_traits>
5#include <limits>
6#include <cstddef>
7
8#include "sanisizer/sanisizer.hpp"
9
10namespace tatami {
11
15template<typename Left_, typename Right_> // provided only for back-compatibility.
16bool safe_non_negative_equal(Left_ l, Right_ r) {
17 return l >= 0 && r >= 0 && sanisizer::is_equal(l, r);
18}
33template<typename Container_, typename Index_>
35 // If the Index_ type is larger than size_t, we cast it to size_t to provide can_cast() with some opportunities for compile-time optimization.
36 // This is because we know that all uses of Index_ must fit into a size_t in order for the Extractor::fetch calls to address the user-supplied arrays.
37 // By casting away larger types, we allow can_cast() to eliminate the run-time overflow checks completely.
38 typedef typename std::conditional<std::numeric_limits<std::size_t>::max() < std::numeric_limits<Index_>::max(), std::size_t, Index_>::type Intermediate;
39 sanisizer::can_cast<decltype(std::declval<Container_>().size())>(static_cast<Intermediate>(x));
40 return x;
41}
42
53template<typename Container_, typename Index_>
54decltype(std::declval<Container_>().size()) cast_Index_to_container_size(Index_ x) {
56}
57
68template<typename Container_, typename Index_>
69Container_ create_container_of_Index_size(Index_ x) {
70 // Same logic as described above.
71 typedef typename std::conditional<std::numeric_limits<std::size_t>::max() < std::numeric_limits<Index_>::max(), std::size_t, Index_>::type Intermediate;
72 return sanisizer::create<Container_>(static_cast<Intermediate>(x));
73}
74
85template<typename Container_, typename Index_>
86void resize_container_to_Index_size(Container_& container, Index_ x) {
88}
89
90}
91
92#endif
Flexible representations for matrix data.
Definition Extractor.hpp:15
Container_ create_container_of_Index_size(Index_ x)
Definition Index_to_container.hpp:69
decltype(std::declval< Container_ >().size()) cast_Index_to_container_size(Index_ x)
Definition Index_to_container.hpp:54
void resize_container_to_Index_size(Container_ &container, Index_ x)
Definition Index_to_container.hpp:86
Index_ can_cast_Index_to_container_size(Index_ x)
Definition Index_to_container.hpp:34