Skip to content

Commit

Permalink
[Type] Deprecate is_container trait
Browse files Browse the repository at this point in the history
  • Loading branch information
alxbilger authored and fredroy committed Jan 17, 2025
1 parent 3635db7 commit a27af78
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Sofa/framework/Helper/src/sofa/helper/OptionsGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include <sofa/type/vector.h>
#include <sofa/helper/config.h>
#include <sofa/type/trait/is_container.h>

namespace sofa::helper
{
Expand Down Expand Up @@ -58,7 +57,7 @@ public :
explicit OptionsGroup(int nbofRadioButton,...);

///generic constructor taking other string container like list<string>, set<string>, vector<string>
template <class T, typename = std::enable_if_t<type::trait::is_container<T>::value> >
template <std::ranges::range T>
explicit OptionsGroup(const T& list);

template <class T> OptionsGroup(const std::initializer_list<T>& list);
Expand Down Expand Up @@ -114,7 +113,7 @@ public :
type::vector<std::string> textItems ;
unsigned int selectedItem ;

template <class T> void buildFromContainer(const T& list);
template <std::ranges::range T> void buildFromContainer(const T& list);

public:

Expand All @@ -137,7 +136,7 @@ inline std::istream & operator >>(std::istream& in, OptionsGroup& m_trick)
return in;
}

template <class T, typename>
template <std::ranges::range T>
OptionsGroup::OptionsGroup(const T& list)
{
buildFromContainer(list);
Expand All @@ -159,7 +158,7 @@ void OptionsGroup::setNames(const std::initializer_list<T>& list)
selectedItem=0;
}

template <class T>
template <std::ranges::range T>
void OptionsGroup::buildFromContainer(const T& list)
{
textItems.reserve(list.size());
Expand Down
9 changes: 9 additions & 0 deletions Sofa/framework/Type/src/sofa/type/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,12 @@
"v24.12", "v25.06", \
"Use isNegligible instead.")
#endif

#ifdef SOFA_BUILD_SOFA_TYPE
#define SOFA_ATTRIBUTE_DEPRECATED__IS_CONTAINER()
#else
#define SOFA_ATTRIBUTE_DEPRECATED__IS_CONTAINER() \
SOFA_ATTRIBUTE_DISABLED( \
"v25.06", "v25.12", \
"Use std::ranges::ranges concept instead.")
#endif
5 changes: 5 additions & 0 deletions Sofa/framework/Type/src/sofa/type/trait/is_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
******************************************************************************/
#pragma once
#include <type_traits>
#include <sofa/type/config.h>

SOFA_HEADER_DEPRECATED_NOT_REPLACED("v25.06", "v25.12")


namespace sofa::type::trait
{

/// Detect if a type T has iterator/const iterator function.
template<typename T>
SOFA_ATTRIBUTE_DEPRECATED__IS_CONTAINER()
struct is_container
{
typedef typename std::remove_const<T>::type test_type;
Expand Down

0 comments on commit a27af78

Please sign in to comment.