sewenew / redis-plus-plus

Redis client written in C++
Apache License 2.0
1.6k stars 347 forks source link

[QUESTION] Unable to use std::optional with redis++ with cpp17 on ubuntu #565

Closed qashoou closed 4 months ago

qashoou commented 4 months ago

Unable to use std::optional with redis++ with cpp17 on ubuntu I am using conan to use redis-plus-plus/1.3.12. I am getting could not convert 'sw::redis::Redis::get(const sw::redis::StringView&)(sw::redis::StringView((* & key)))' from 'sw::redis::OptionalString' {aka 'sw::redis::Optional<std::__cxx11::basic_string<char> >'} to 'std::optional<std::__cxx11::basic_string<char> >' 44 | return redis.get(key);

Everywhere i read that with cpp17 (with complete stdcpp, not the experimental versions), we get to use the std::optional. but, I am unable to get that to work.

I have tried the following solutions.

  1. Set redis++ cpp version to 17 using: -DREDIS_PLUS_PLUS_CXX_STANDARD=17
  2. forced conan cpp version to 17 (though it was already set as default)
  3. forced redis++ to be build everytime using. conan_cmake_run(CONANFILE conanfile.txt BASIC_SETUP CMAKE_TARGETS SETTINGS cppstd=17 BUILD redis-plus-plus)

Any and all help is appreciated.

Environment:

qashoou commented 4 months ago

Another finding. I checked the sources, even though the latest version defaults to cpp17 version of cxx_utils.h, but my conan sources show the following. image

This means, the version 1.3.12 has cpp11 version.

sewenew commented 4 months ago

Yes, that means that you built and installed redis-plus-plus with C++11, not C++17.

I'm not familiar with Conan, but I tried it on ubuntu 24.04 with this tutorial and the following CMakeLists.txt, and cannot reproduce your problem, i.e. C++ 17 version of cxx_util.h is installed correctly.

cmake_minimum_required(VERSION 3.1)
project(demo)

find_package(redis++ REQUIRED)

add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} redis++::redis++_static)

I'd suggest you ask help from some Conan expert.

Regards

qashoou commented 4 months ago

Thanks for the reply @sewenew. but if you check the sources of the conan package, they say its the latest one. do you know who manages the conan package or redis++?

sewenew commented 4 months ago

Sorry, I don't know who is the maintainer. Maybe you can create an issue on Conan for help.

Regards

qashoou commented 4 months ago

thanks

jforozcoo commented 4 months ago

Hello @qashoou

Did you solve the problem?

I have te same issue