Skip to content

Commit c94ef84

Browse files
fix(ofParameter): ctor refinements for std::string (#8279)
Co-authored-by: alexandre burton <[email protected]>
1 parent 29499c0 commit c94ef84

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

libs/openFrameworks/types/ofParameter.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,16 +514,24 @@ class ofParameter : public ofAbstractParameter {
514514

515515
/// \brief constructs an ofParameter of type ParameterType initialized to value of v
516516
/// where v is convertible to ParameterType, with an exception for bool which can cause
517-
/// unexpected behavious (as string and char arrays are convertible to bool)
517+
/// unexpected behavious (as string and char arrays are convertible to bool) and
518+
/// the exception of a single string-convertible argument with std::string ParameterType
518519
/// \tparam ParameterType the type of the value held by the ofParameter
519520
/// \tparam Arg a type convertible to ParameterType
520521
/// \param v the value to initialize to
521522
template <
522523
typename Arg,
523-
typename = std::enable_if_t<(std::is_convertible_v<Arg, ParameterType> and
524+
typename = std::enable_if_t<(!(std::is_convertible_v<Arg, std::string> and std::is_same_v<ParameterType, std::string>) and
525+
std::is_convertible_v<Arg, ParameterType> and
524526
!((std::is_same_v<ParameterType, bool>)and!(std::is_arithmetic_v<Arg>)))>>
525527
ofParameter(const Arg & v);
526528

529+
/// \brief constructs an ofParameter<std::string> initialized to value of v
530+
/// \tparam ParameterType the type of the value held by the ofParameter
531+
/// \param v the string value to initialize to
532+
template <typename U = ParameterType, typename = std::enable_if_t<std::is_same_v<U, std::string>>>
533+
ofParameter(const std::string & v);
534+
527535
/// \brief constructs a named ofParameter of type ParameterType initialized to value of v
528536
/// \tparam ParameterType the type of the value held by the ofParameter
529537
/// \param name name of the parameter
@@ -724,6 +732,12 @@ ofParameter<ParameterType>::ofParameter(const Arg & v)
724732
: obj(std::make_shared<Value>(v))
725733
, setMethod(std::bind(&ofParameter<ParameterType>::eventsSetValue, this, std::placeholders::_1)) { }
726734

735+
template <typename ParameterType>
736+
template <typename U, typename>
737+
ofParameter<ParameterType>::ofParameter(const std::string & v)
738+
: obj(std::make_shared<Value>(v))
739+
, setMethod(std::bind(&ofParameter<std::string>::eventsSetValue, this, std::placeholders::_1)) { }
740+
727741
template <typename ParameterType>
728742
ofParameter<ParameterType>::ofParameter(const std::string & name, const ParameterType & v)
729743
: obj(std::make_shared<Value>(name, v))

0 commit comments

Comments
 (0)