Commit beda6f85 authored by Ben Huber's avatar Ben Huber

replaced index constructors from specific signed / unsigned integers by...

replaced index constructors from specific signed / unsigned integers by template versions; should be more general and fix a compilation error on macOS (relates #205)
parent 70aa8d02
Pipeline #902 passed with stages
in 8 minutes and 48 seconds
...@@ -73,28 +73,31 @@ namespace xerus { ...@@ -73,28 +73,31 @@ namespace xerus {
/// @brief Empty constructor that creates a new Index with new ID. Use this to create indices. /// @brief Empty constructor that creates a new Index with new ID. Use this to create indices.
Index(); Index() : valueId(idCounter++), span(1) { };
/// @brief Indices are default copy constructable. /// @brief Indices are default copy constructable.
Index(const Index& _other) noexcept = default; Index(const Index& _other) noexcept = default;
/// @brief Integers are implicitly allowed to be casted to Index, to allow expression as A(i) = B(3,i), i.e. A is the third row of B. /// @brief Integers are implicitly allowed to be casted to Index, to allow expression as A(i) = B(3,i), i.e. A is the third row of B.
Index(const int32 _i); template<class I, typename std::enable_if<std::is_integral<I>::value && std::is_unsigned<I>::value, bool>::type = true>
Index(const I _i) noexcept : valueId(_i), span(1) {
flags[Flag::FIXED] = true;
}
/// @brief Integers are implicitly allowed to be casted to Index, to allow expression as A(i) = B(3,i), i.e. A is the third row of B. /// @brief Integers are implicitly allowed to be casted to Index, to allow expression as A(i) = B(3,i), i.e. A is the third row of B.
Index(const uint32 _i) noexcept; template<class I, typename std::enable_if<std::is_integral<I>::value && !std::is_unsigned<I>::value, bool>::type = true>
Index(const I _i) : Index(static_cast<uint64>(_i)) {
/// @brief Integers are implicitly allowed to be casted to Index, to allow expression as A(i) = B(3,i), i.e. A is the third row of B. using ::xerus::misc::operator<<;
Index(const int64 _i); XERUS_REQUIRE(_i >= 0, "Negative valueId= " <<_i<< " given");
}
/// @brief Integers are implicitly allowed to be casted to Index, to allow expression as A(i) = B(3,i), i.e. A is the third row of B.
Index(const uint64 _i) noexcept;
/// @brief Internal constructor, do not use this unless you know what you are doing. /// @brief Internal constructor, do not use this unless you know what you are doing.
explicit Index(const uint64 _valueId, const size_t _span) noexcept; explicit Index(const uint64 _valueId, const size_t _span) noexcept : valueId(_valueId), span(_span) {};
/// @brief Internal constructor, do not use this unless you know what you are doing. /// @brief Internal constructor, do not use this unless you know what you are doing.
explicit Index(const uint64 _valueId, const size_t _span, const Flag _flag1) noexcept; explicit Index(const uint64 _valueId, const size_t _span, const Flag _flag1) noexcept : valueId(_valueId), span(_span) {
flags[_flag1] = true;
}
......
...@@ -34,33 +34,6 @@ namespace xerus { ...@@ -34,33 +34,6 @@ namespace xerus {
thread_local uint64 Index::idCounter = (idThreadInitCounter++)<<54; thread_local uint64 Index::idCounter = (idThreadInitCounter++)<<54;
Index::Index() : valueId(idCounter++), span(1) { }
Index::Index(const int32 _i) : Index(static_cast<uint64>(_i)) {
REQUIRE(_i >= 0, "Negative valueId= " <<_i<< " given");
}
Index::Index(const uint32 _i) noexcept : valueId(_i), span(1) {
flags[Flag::FIXED] = true;
}
Index::Index(const int64 _i) : Index(static_cast<uint64>(_i)) {
REQUIRE(_i >= 0, "Negative valueId= " <<_i<< " given");
}
Index::Index(const uint64 _i) noexcept : valueId(_i), span(1) {
flags[Flag::FIXED] = true;
}
Index::Index(const uint64 _valueId, const size_t _span) noexcept : valueId(_valueId), span(_span) {}
Index::Index(const uint64 _valueId, const size_t _span, const Flag _flag1) noexcept : valueId(_valueId), span(_span) {
flags[_flag1] = true;
}
void Index::set_span(const size_t _degree) { void Index::set_span(const size_t _degree) {
REQUIRE(!flags[Flag::FIXED] || span == 1, "Fixed indices must have span one."); REQUIRE(!flags[Flag::FIXED] || span == 1, "Fixed indices must have span one.");
if(flags[Flag::INVERSE_SPAN]) { if(flags[Flag::INVERSE_SPAN]) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment