Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Type] Convert is_vector trait to concept #5201

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class BaseContext::GetObjectsCallBackT : public BaseContext::GetObjectsCallBack
GetObjectsCallBackT(Container* d) : dest(d) {}
void operator()(void* ptr) override
{
if constexpr (sofa::type::trait::is_vector<Container>::value)
if constexpr (sofa::type::trait::is_vector<Container>)
{
dest->push_back(reinterpret_cast<T*>(ptr));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ReadAccessor<FixedArrayLikeType, std::enable_if_t<sofa::type::trait::is_fi

template<class VectorLikeType>
class ReadAccessor<VectorLikeType,
std::enable_if_t<sofa::type::trait::is_vector<VectorLikeType>::value> >
std::enable_if_t<sofa::type::trait::is_vector<VectorLikeType>> >
: public ReadAccessorVector< VectorLikeType >
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class WriteAccessor<FixedArrayLikeType, std::enable_if_t<sofa::type::trait::is_f

template<class VectorLikeType>
class WriteAccessor<VectorLikeType,
std::enable_if_t<sofa::type::trait::is_vector<VectorLikeType>::value>>
std::enable_if_t<sofa::type::trait::is_vector<VectorLikeType>>>
: public WriteAccessorVector< VectorLikeType >
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class WriteOnlyAccessor : public WriteAccessor<T, Enable>

template<class VectorLikeType>
class WriteOnlyAccessor<VectorLikeType,
std::enable_if_t<sofa::type::trait::is_vector<VectorLikeType>::value> >
std::enable_if_t<sofa::type::trait::is_vector<VectorLikeType>> >
: public WriteAccessorVector< VectorLikeType >
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ class CompressedRowSparseMatrixMechanical final // final is used to allow the co

/// equal result = this * v
/// @warning The block sizes must be compatible ie v.size() must be a multiple of block size.
template< typename V1, typename V2, std::enable_if_t<sofa::type::trait::is_vector<V1>::value && sofa::type::trait::is_vector<V2>::value, int> = 0 >
template< typename V1, typename V2, std::enable_if_t<sofa::type::trait::is_vector<V1> && sofa::type::trait::is_vector<V2>, int> = 0 >
void mul( V2& result, const V1& v ) const
{
this-> template tmul< Real, V2, V1 >(result, v);
Expand Down
36 changes: 7 additions & 29 deletions Sofa/framework/Type/src/sofa/type/trait/is_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,16 @@ namespace sofa::type::trait

/// Detect if a type T has iterator/const iterator function, operator[](size_t) and is dynamically resizable (resize function)
template<typename T>
struct is_vector
concept is_vector = requires(std::remove_cv_t<T> t, const std::remove_cv_t<T> ct)
{
typedef typename std::remove_const<T>::type test_type;
t.begin() -> T::iterator;
t.end() -> T::iterator;

template<typename A>
static constexpr bool test(
A * pt,
A const * cpt = nullptr,
decltype(pt->begin()) * = nullptr,
decltype(pt->end()) * = nullptr,
decltype(cpt->begin()) * = nullptr,
decltype(cpt->end()) * = nullptr,
typename std::decay<decltype((*pt)[0])>::type * = nullptr, ///< Is there an operator[] ?
decltype(pt->resize(1)) * = nullptr,
typename A::iterator * = nullptr,
typename A::const_iterator * = nullptr,
typename A::value_type * = nullptr) {
ct.begin() -> T::const_iterator;
ct.end() -> T::const_iterator;

typedef typename A::iterator iterator;
typedef typename A::const_iterator const_iterator;
return std::is_same<decltype(pt->begin()),iterator>::value
&& std::is_same<decltype(pt->end()),iterator>::value
&& std::is_same<decltype(cpt->begin()),const_iterator>::value
&& std::is_same<decltype(cpt->end()),const_iterator>::value;
}

template<typename A>
static constexpr bool test(...) {
return false;
}

static const bool value = test<test_type>(nullptr);
t[0];
t.resize(1);
};

}
Loading