Skip to content

Commit

Permalink
Fixed compilation issues with Clang and GCC on Linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil MacIntosh committed Sep 14, 2015
1 parent 17ed5c3 commit ef6cc65
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 191 deletions.
33 changes: 19 additions & 14 deletions include/array_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ class index : private details::coordinate_facade<index<Rank, ValueType>, ValueTy
}
_CONSTEXPR static index shift_left(const index<rank+1, value_type>& other) _NOEXCEPT
{
return (value_type(&)[rank])other.elems[1];
value_type (&arr)[rank] = (value_type(&)[rank])(*(other.elems + 1));
return index(arr);
}

using Base::operator[];
Expand Down Expand Up @@ -1647,7 +1648,8 @@ class array_view : public basic_array_view<typename details::ArrayViewTypeTraits
using typename Base::index_type;
using typename Base::iterator;
using typename Base::const_iterator;
using Base::rank;
using typename Base::reference;
using Base::rank;

public:
// basic
Expand Down Expand Up @@ -1848,14 +1850,16 @@ class array_view : public basic_array_view<typename details::ArrayViewTypeTraits
// section
_CONSTEXPR strided_array_view<ValueTypeOpt, rank> section(index_type origin, index_type extents) const
{
size_type size = bounds().total_size() - bounds().linearize(origin);
size_type size = this->bounds().total_size() - this->bounds().linearize(origin);
return{ &this->operator[](origin), size, strided_bounds<rank, size_type> {extents, details::make_stride(Base::bounds())} };
}
_CONSTEXPR reference operator[](const index_type& idx) const

_CONSTEXPR reference operator[](const index_type& idx) const
{
return Base::operator[](idx);
}
template <bool Enabled = (rank > 1), typename Dummy = std::enable_if_t<Enabled>>

template <bool Enabled = (rank > 1), typename Dummy = std::enable_if_t<Enabled>>
_CONSTEXPR array_view<ValueTypeOpt, RestDimensions...> operator[](size_type idx) const
{
auto ret = Base::operator[](idx);
Expand Down Expand Up @@ -1936,6 +1940,7 @@ class strided_array_view : public basic_array_view<typename details::ArrayViewTy
using typename Base::index_type;
using typename Base::iterator;
using typename Base::const_iterator;
using typename Base::reference;

// from static array of size N
template<size_type N>
Expand Down Expand Up @@ -1968,26 +1973,26 @@ class strided_array_view : public basic_array_view<typename details::ArrayViewTy
}

// convert from bytes
template <typename OtherValueType, typename Dummy = std::enable_if_t<std::is_same<value_type, const byte>::value>>
strided_array_view<OtherValueType, rank> as_strided_array_view() const
template <typename OtherValueType>
strided_array_view<typename std::enable_if<std::is_same<value_type, const byte>::value, OtherValueType>::type, rank> as_strided_array_view() const
{
static_assert((sizeof(OtherValueType) >= sizeof(value_type)) && (sizeof(OtherValueType) % sizeof(value_type) == 0), "OtherValueType should have a size to contain a multiple of ValueTypes");
auto d = sizeof(OtherValueType) / sizeof(value_type);

size_type size = bounds().total_size() / d;
return{ (OtherValueType*)data(), size, bounds_type{ resize_extent(bounds().index_bounds(), d), resize_stride(bounds().strides(), d)} };
size_type size = this->bounds().total_size() / d;
return{ (OtherValueType*)this->data(), size, bounds_type{ resize_extent(this->bounds().index_bounds(), d), resize_stride(this->bounds().strides(), d)} };
}

strided_array_view section(index_type origin, index_type extents) const
{
size_type size = bounds().total_size() - bounds().linearize(origin);
size_type size = this->bounds().total_size() - this->bounds().linearize(origin);
return { &this->operator[](origin), size, bounds_type {extents, details::make_stride(Base::bounds())}};
}

_CONSTEXPR reference operator[](const index_type& idx) const
{
return Base::operator[](idx);
}
{
return Base::operator[](idx);
}

template <bool Enabled = (rank > 1), typename Dummy = std::enable_if_t<Enabled>>
_CONSTEXPR strided_array_view<value_type, rank-1> operator[](size_type idx) const
Expand Down Expand Up @@ -2048,7 +2053,7 @@ class contiguous_array_view_iterator : public std::iterator<std::random_access_i
const ArrayView * m_validator;
void validateThis() const
{
fail_fast_assert(m_pdata >= m_validator->m_pdata && m_pdata < m_validator->m_pdata + m_validator->size(), "iterator is out of range of the array");
fail_fast_assert(m_pdata >= m_validator->m_pdata && m_pdata < m_validator->m_pdata + m_validator->size());
}
contiguous_array_view_iterator (const ArrayView *container, bool isbegin = false) :
m_pdata(isbegin ? container->m_pdata : container->m_pdata + container->size()), m_validator(container) { }
Expand Down
11 changes: 4 additions & 7 deletions include/fail_fast.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ namespace Guide
//
#if defined(SAFER_CPP_TESTING)

struct fail_fast : public std::exception
struct fail_fast : public std::runtime_error
{
fail_fast() = default;

explicit fail_fast(char const* const message) :
std::exception(message)
{}
fail_fast() : std::runtime_error("") {}
explicit fail_fast(char const* const message) : std::runtime_error(message) {}
};

inline void fail_fast_assert(bool cond) { if (!cond) throw fail_fast(); }
Expand All @@ -46,4 +43,4 @@ inline void fail_fast_assert(bool cond, const char* const message) { if (!cond)

#endif // SAFER_CPP_TESTING

}
}
Loading

0 comments on commit ef6cc65

Please sign in to comment.