Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Cannot construct Opt from lambda when passed via variable #58

Open
lethal-guitar opened this issue Mar 3, 2018 · 0 comments
Open

Cannot construct Opt from lambda when passed via variable #58

lethal-guitar opened this issue Mar 3, 2018 · 0 comments

Comments

@lethal-guitar
Copy link

The following code fails to compile for me on Apple Clang (Apple LLVM version 8.0.0 (clang-800.0.42.1; Target: x86_64-apple-darwin15.6.0):

#include <clara.hpp>
#include <string>

int main(int argc, char** argv) {
  bool showHelp = false;

  auto parsePlayerPos = [](const std::string& playerPosString) { /* Do something here */ };

  using namespace clara;
  auto commandLineParser =
    Help(showHelp)
    | Opt(parsePlayerPos, "player-pos")
      ["--player-pos"]
      ("Some text here");

  return 0;
}

if I specify the lambda expression inline, it works, i.e.:

Opt([](const std::string& playerPosString) { /* Do something here */ }, "player-pos")

The error message I get is:

In file included from /Users/lethal-guitar/RigelEngine/src/main.cpp:20:
/Users/lethal-guitar/RigelEngine/3rd_party/clara/clara.hpp:640:12: error: invalid operands to binary expression ('std::stringstream'
      (aka 'basic_stringstream<char>') and '(lambda at /Users/lethal-guitar/RigelEngine/src/main.cpp:29:25)')
        ss >> target;
        ~~ ^  ~~~~~~
/Users/lethal-guitar/RigelEngine/3rd_party/clara/clara.hpp:690:20: note: in instantiation of function template specialization
      'clara::detail::convertInto<(lambda at /Users/lethal-guitar/RigelEngine/src/main.cpp:29:25)>' requested here
            return convertInto( arg, m_ref );
                   ^
/Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/memory:2125:7: note: in instantiation of member function
      'clara::detail::BoundValueRef<(lambda at /Users/lethal-guitar/RigelEngine/src/main.cpp:29:25)>::setValue' requested here
class __libcpp_compressed_pair_imp<_T1, _T2, 1>
      ^
/Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/memory:4411:26: note: in instantiation of function template specialization
      'std::__1::__shared_ptr_emplace<clara::detail::BoundValueRef<(lambda at /Users/lethal-guitar/RigelEngine/src/main.cpp:29:25)>,
      std::__1::allocator<clara::detail::BoundValueRef<(lambda at /Users/lethal-guitar/RigelEngine/src/main.cpp:29:25)> >
      >::__shared_ptr_emplace<(lambda at /Users/lethal-guitar/RigelEngine/src/main.cpp:29:25) &>' requested here
    ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
                         ^
/Library/Developer/CommandLineTools/usr/bin/../include/c  /v1/memory:4775:29: note: in instantiation of function template specialization
      'std::__1::shared_ptr<clara::detail::BoundValueRef<(lambda at /Users/lethal-guitar/RigelEngine/src/main.cpp:29:25)>
      >::make_shared<(lambda at /Users/lethal-guitar/RigelEngine/src/main.cpp:29:25) &>' requested here
    return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
                            ^
/Users/lethal-guitar/RigelEngine/3rd_party/clara/clara.hpp:817:25: note: in instantiation of function template specialization
      'std::__1::make_shared<clara::detail::BoundValueRef<(lambda at /Users/lethal-guitar/RigelEngine/src/main.cpp:29:25)>, (lambda at
      /Users/lethal-guitar/RigelEngine/src/main.cpp:29:25) &>' requested here
        :   m_ref( std::make_shared<BoundValueRef<T>>( ref ) ),
                        ^
/Users/lethal-guitar/RigelEngine/3rd_party/clara/clara.hpp:946:50: note: in instantiation of function template specialization
      'clara::detail::ParserRefImpl<clara::detail::Opt>::ParserRefImpl<(lambda at /Users/lethal-guitar/RigelEngine/src/main.cpp:29:25)>'
      requested here
        Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {}
                                                 ^
/Users/lethal-guitar/RigelEngine/src/main.cpp:35:7: note: in instantiation of function template specialization
      'clara::detail::Opt::Opt<(lambda at /Users/lethal-guitar/RigelEngine/src/main.cpp:29:25)>' requested here
    | Opt(parsePlayerPos, "player-pos")

I'm using Clara v. 1.1.2.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant