Menu

#20 Change ValuesConstraint constructor to take const&

1.4
closed-fixed
None
5
2025-06-23
2025-06-19
No

The following patch against 1.4.0-rc2 changes the ValuesConstraint ctor to take its argument as const. This enables convenient usage with initializer lists such as this: const ValuesConstraint<std::string> wtConstraint({"type-a","type-c"});

diff --git a/common_headers/tclap/include/tclap/ValuesConstraint.h b/common_headers/tclap/include/tclap/ValuesConstraint.h
index cee236d1..9819199d 100644
--- a/common_headers/tclap/include/tclap/ValuesConstraint.h
+++ b/common_headers/tclap/include/tclap/ValuesConstraint.h
@@ -43,7 +43,7 @@ public:
      * Constructor.
      * \param allowed - vector of allowed values.
      */
-    explicit ValuesConstraint(std::vector<T> &allowed);
+    explicit ValuesConstraint(const std::vector<T> &allowed);

     /**
      * Virtual destructor.
@@ -80,7 +80,7 @@ protected:
 };

 template <class T>
-ValuesConstraint<T>::ValuesConstraint(std::vector<T> &allowed)
+ValuesConstraint<T>::ValuesConstraint(const std::vector<T> &allowed)
     : _allowed(allowed), _typeDesc("") {
     for (unsigned int i = 0; i < _allowed.size(); i++) {
         std::ostringstream os;

Discussion

  • Daniel Aarno

    Daniel Aarno - 2025-06-23
    • status: open --> closed-fixed
    • assigned_to: Daniel Aarno
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.