まあ、私は最終的に私のために働くように見える解決策を見つけました。可能であれば、流暢な誰かからの独立した検証があればいいのですboost::program_options
が、どうやら誰もそれをあまり知らないか、気にかけていないようです。
これは、boost_1_49_0のパッチであり、オプションをcomposed()にすると同時に、implicit_value()を持つこともできます。
diff -Naur old/boost/program_options/detail/value_semantic.hpp new/boost/program_options/detail/value_semantic.hpp
--- old/boost/program_options/detail/value_semantic.hpp 2010-07-12 03:14:14.000000000 -0400
+++ new/boost/program_options/detail/value_semantic.hpp 2012-08-17 16:31:03.000000000 -0400
@@ -154,6 +154,28 @@
}
}
+ // Helper function to copy a non-vector implicit value into the
+ // tokens vector.
+ template<class T, class charT>
+ void get_implicit_tokens(std::vector<std::basic_string<charT> >& vs,
+ const boost::any& a,
+ T*, long) {
+ const T va = boost::any_cast<const T>(a);
+ vs.push_back(boost::lexical_cast<std::basic_string<charT> >(va));
+ }
+
+ // Helper function to copy a vector implicit value into the
+ // tokens vector.
+ template<class T, class charT>
+ void get_implicit_tokens(std::vector<std::basic_string<charT> >& vs,
+ const boost::any& a,
+ std::vector<T>*, int) {
+ const std::vector<T> va = boost::any_cast<const std::vector<T> >(a);
+ for (unsigned i = 0; i < va.size(); i++) {
+ vs.push_back(boost::lexical_cast<std::basic_string<charT> >(va[i]));
+ }
+ }
+
template<class T, class charT>
void
typed_value<T, charT>::
@@ -164,7 +186,14 @@
// value, then assign the implicit value as the stored value;
// otherwise, validate the user-provided token(s).
if (new_tokens.empty() && !m_implicit_value.empty())
- value_store = m_implicit_value;
+ if (m_composing) {
+ // Attempt to append the implicit value.
+ std::vector<std::basic_string<charT> > vs;
+ get_implicit_tokens(vs, m_implicit_value, (T*)0, 0);
+ validate(value_store, vs, (T*)0, 0);
+ } else {
+ value_store = m_implicit_value;
+ }
else
validate(value_store, new_tokens, (T*)0, 0);
}