sewenew/redis-plus-plus

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

qashoou opened this issue · 6 comments

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:

  • OS: Ubuntu 22.04 LTS
  • Compiler: gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)
  • hiredis version: hiredis/1.2.0 from 'conan-center-io'
  • redis-plus-plus version: 1.3.12

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.

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

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++?

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

Regards

thanks

Hello @qashoou

Did you solve the problem?

I have te same issue