doom_Oo7

u/doom_Oo7


r/cpp_questions•

Hello,

I am trying to simplify some code thanks to C++17 new features.

In particular, I was interested in template<auto> : the promise was that it would help to simplify passing callback functions, e.g. no need anymore to do stuff such as template<typename T, typename R, R (T::*ptr)(Args...)> to pass member functions. (see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0127r1.html section "Motivation")

In practice, I had existing code that was doing the following :

 connect<MyClass, &MyClass::blah>(...);  

which I wanted to shorten to

 connect<&MyClass::blah>(...);  

alas ! It apparently only works with non-template arguments, an

37


r/cpp_questions•

Given the following example :

CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(export_templates CXX)
include(GenerateExportHeader)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

add_library(mylib SHARED header.hpp mylib.cpp)
generate_export_header(mylib)

add_executable(myexe header.hpp main.cpp)
target_link_libraries(myexe mylib)

header.hpp:

#pragma once
#include <vector>
template<typename T>
struct foo
{
    std::size_t bar() {
        std::vector<T> t;
        t.resize(10);
        return t.size();
    }
};

extern template st
43

r/Qt5•

Hello everyone, I have been granted moderation rights for this subreddit due to the inactivity of its previous mod. I've started cleaning up the chinese spam and rejuvenating the links on the right side with more up-to-date information.

I will leave this post sticky for some time: if anyone has ideas for improvements or see missing things, please share it here :)

195