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_fixed_array trait to concept #5209

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions Sofa/framework/Helper/src/sofa/helper/accessor/ReadAccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class ReadAccessor
const_reference operator* () const { return *vref; }
};

template<class FixedArrayLikeType>
class ReadAccessor<FixedArrayLikeType, std::enable_if_t<sofa::type::trait::is_fixed_array<FixedArrayLikeType>::value>>
template<sofa::type::trait::is_fixed_array FixedArrayLikeType>
class ReadAccessor<FixedArrayLikeType>
: public ReadAccessorFixedArray< FixedArrayLikeType >
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace sofa::helper
{
////////////////////////// ReadAccessor for wrapping around fixed array like object //////////////////////
/// ReadAccessor implementation class for fixed array types
template<class T>
template<type::trait::is_fixed_array T>
class ReadAccessorFixedArray
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ class WriteAccessor
}
};

template<class FixedArrayLikeType>
class WriteAccessor<FixedArrayLikeType, std::enable_if_t<sofa::type::trait::is_fixed_array<FixedArrayLikeType>::value>>
template<type::trait::is_fixed_array FixedArrayLikeType>
class WriteAccessor<FixedArrayLikeType>
: public WriteAccessorFixedArray< FixedArrayLikeType >
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace sofa::helper
{

/// WriteAccessor implementation class for fixed array types
template<class T>
template<type::trait::is_fixed_array T>
class WriteAccessorFixedArray
{
public:
Expand Down
36 changes: 7 additions & 29 deletions Sofa/framework/Type/src/sofa/type/trait/is_fixed_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,17 @@ namespace sofa::type::trait

/// Detect if a type T has iterator/const iterator function, operator[](size_t) and defines a static size
template<typename T>
struct is_fixed_array
concept is_fixed_array = requires(std::remove_cv_t<T> t, const std::remove_cv_t<T> ct)
{
typedef typename std::remove_const<T>::type test_type;
T::static_size;

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(A::static_size) * = nullptr, ///< fixed array containers define static_size
typename A::iterator * = nullptr,
typename A::const_iterator * = nullptr,
typename A::value_type * = nullptr)
{
{t.begin()} -> std::convertible_to<typename T::iterator>;
{t.end()} -> std::convertible_to<typename T::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;
}
{ct.begin()} -> std::convertible_to<typename T::const_iterator>;
{ct.end()} -> std::convertible_to<typename T::const_iterator>;

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

static const bool value = test<test_type>(nullptr);
{ t[0] } -> std::convertible_to<typename T::value_type>;
};

}
Loading