Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-588

Cannot use kvp() with a std::string parameter

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 0.2.0
    • Affects Version/s: None
    • Component/s: API
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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
      

        1. kvp.cpp
          0.3 kB

            Assignee:
            mira.carey@mongodb.com Mira Carey
            Reporter:
            yhager Yuval Hager
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: