[CXX-588] Cannot use kvp() with a std::string parameter Created: 29/Apr/15  Updated: 15/May/15  Resolved: 13/May/15

Status: Closed
Project: C++ Driver
Component/s: API
Affects Version/s: None
Fix Version/s: 0.2.0

Type: Bug Priority: Major - P3
Reporter: Yuval Hager Assignee: Mira Carey
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File kvp.cpp    
Epic Link: PM-123

 Description   

Using kvp("foo", "bar") as the examples show works fine. However, this doesn't:

  std::string foo = "foo";
  kvp(foo, "bar");

It seems to cause a problem with template deduction.
Attached is a example file that I cannot compile. The error I get is:

In file included from /home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/impl.hpp:20:0,
                 from /home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/document.hpp:19,
                 from /home/yuval/work/js/mongo-cxx-driver/examples/bsoncxx/kvp.cpp:1:
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp: In instantiation of ‘void bsoncxx::v0::builder::basic::sub_document::append(Arg&&, Args&& ...) [with Arg = std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, const char (&)[4]>; Args = {}]’:
/home/yuval/work/js/mongo-cxx-driver/examples/bsoncxx/kvp.cpp:14:31:   required from here
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp:48:9: error: no matching function for call to ‘bsoncxx::v0::builder::basic::sub_document::append()’
         append(std::forward<Args>(args)...);
         ^
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp:48:9: note: candidates are:
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp:46:10: note: template<class Arg, class ... Args> void bsoncxx::v0::builder::basic::sub_document::append(Arg&&, Args&& ...)
     void append(Arg&& a, Args&&... args) {
          ^
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp:46:10: note:   template argument deduction/substitution failed:
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp:48:9: note:   candidate expects 2 arguments, 0 provided
         append(std::forward<Args>(args)...);
         ^
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp:56:10: note: template<class T> void bsoncxx::v0::builder::basic::sub_document::append(std::tuple<core::v1::basic_string_view<char, std::char_traits<char> >, T>&&)
     void append(std::tuple<stdx::string_view, T>&& t) {
          ^
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp:56:10: note:   template argument deduction/substitution failed:
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp:48:9: note:   candidate expects 1 argument, 0 provided
         append(std::forward<Args>(args)...);
         ^
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp:66:10: note: template<class T> void bsoncxx::v0::builder::basic::sub_document::append(std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, T>&&)
     void append(std::tuple<std::string, T>&& t) {
          ^
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp:66:10: note:   template argument deduction/substitution failed:
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp:48:9: note:   candidate expects 1 argument, 0 provided
         append(std::forward<Args>(args)...);
         ^
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp:76:10: note: template<long unsigned int n, class T> void bsoncxx::v0::builder::basic::sub_document::append(std::tuple<const char (&)[n], T>&&)
     void append(std::tuple<const char (&)[n], T>&& t) {
          ^
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp:76:10: note:   template argument deduction/substitution failed:
/home/yuval/work/js/mongo-cxx-driver/build-examples/install/include/bsoncxx/v0.2/bsoncxx/builder/basic/sub_document.hpp:48:9: note:   candidate expects 1 argument, 0 provided
         append(std::forward<Args>(args)...);
         ^
examples/bsoncxx/CMakeFiles/kvp.dir/build.make:54: recipe for target 'examples/bsoncxx/CMakeFiles/kvp.dir/kvp.cpp.o' failed
make[2]: *** [examples/bsoncxx/CMakeFiles/kvp.dir/kvp.cpp.o] Error 1
CMakeFiles/Makefile2:826: recipe for target 'examples/bsoncxx/CMakeFiles/kvp.dir/all' failed
make[1]: *** [examples/bsoncxx/CMakeFiles/kvp.dir/all] Error 2
Makefile:126: recipe for target 'all' failed
make: *** [all] Error 2



 Comments   
Comment by Githook User [ 13/May/15 ]

Author:

{u'username': u'hanumantmk', u'name': u'Jason Carey', u'email': u'jcarey@argv.me'}

Message: CXX-588 Cannot use kvp() with a std::string param

sub_document.append() specializations for std::string and
stdx::string_view keyed tuples fail to forward for the various cv and
ref qualified variants. To keep up the perfect forwarding, these
functions need to take the key type as a template type parameter and
SFINAE themselves to disambiguate.

Closes #291, #281

Signed-off-by: Adam Midvidy <amidvidy@gmail.com>
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/050b88146c99dac06725210ce7fd4b3ab8dc80f6

Comment by Yuval Hager [ 13/May/15 ]

This PR had a comment by @amidvidy for a while. I've tried that suggestion, and it worked, so I took that PR and modified it accordingly.

https://github.com/mongodb/mongo-cxx-driver/pull/291

Comment by Yuval Hager [ 30/Apr/15 ]

Thank you for the speedy response!

Comment by Mira Carey [ 29/Apr/15 ]

https://github.com/mongodb/mongo-cxx-driver/pull/281

Comment by Andrew Morrow (Inactive) [ 29/Apr/15 ]

Thank you for the bug report. We appreciate your experimenting with the C++11 driver alpha.

Generated at Wed Feb 07 21:59:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.