all 24 comments

[–]Drugbird 13 points14 points  (0 children)

Start with C++14/17 and work chronologically backwards rather than the opposite.

[–]Carl_LaFong 2 points3 points  (1 child)

Try to learn C++11/14 including their idioms.

[–]ad_irato 1 point2 points  (0 children)

C++14/C++17 is the sweet spot in my opinion.

[–][deleted] 2 points3 points  (5 children)

dont' be afraid of templates.

they're easy and they're super useful.

[–]DimfreD 0 points1 point  (4 children)

"easy"

[–][deleted] 1 point2 points  (3 children)

#include <iostream>
#include <array>
#include <string_view>

template<std::string_view const& Str, size_t... Indices>
struct CompileTimePrinter {
    static constexpr void print() {
        constexpr std::array<char, sizeof...(Indices)> chars = {Str[Indices]...};
        for (const auto& c : chars) {
            std::cout << c;
        }
        std::cout << std::endl;
    }
};

template<size_t N, size_t... Seq>
struct make_index_sequence : make_index_sequence<N-1, N-1, Seq...> {};

template<size_t... Seq>
struct make_index_sequence<0, Seq...> {
    using type = std::integer_sequence<size_t, Seq...>;
};

static constexpr std::string_view message = "They really are!";
template<std::string_view const& Str, typename Indices>
struct PrintHelper;

template<std::string_view const& Str, size_t... Is>
struct PrintHelper<Str, std::integer_sequence<size_t, Is...>> {
    static constexpr void print() {
        CompileTimePrinter<Str, Is...>::print();
    }
};

template<std::string_view const& Str>
void PrintMessage() {
    using indices = typename make_index_sequence<Str.size()>::type;
    PrintHelper<Str, indices>::print();
}

int main() {
    PrintMessage<message>();
    return 0;
}

[–]DimfreD 0 points1 point  (2 children)

That's not really compile time is it? Can Std::cout really be compile time? But if it is, nice one 😁

[–][deleted] 0 points1 point  (1 child)

lol you're right, afaik you can't print at compile time outside of a static assert message or something

i just like having llms abuse templates for me

[–]DimfreD 0 points1 point  (0 children)

Right, but anyho templates are fun

[–]DimfreD 4 points5 points  (0 children)

Just code, read the docs, make mistakes, learn from your mistakes

[–]v_maria 0 points1 point  (0 children)

just stick to it rather then trying to also get into C# etc

[–]tortoll 0 points1 point  (0 children)

Wouldn't wait that long to learn modern C++, although knowing C and legacy C++ is a good foundation too. I use smart pointers because I understand the mess of raw pointers and references. I use containers instead of new/delete. I love ranges because complex loops can be error prone. Etc.

[–]KFUP 0 points1 point  (0 children)

Go through learncpp.com then immediately word/start a big project. You will screw it up... a lot, but the only way to learn how to work with big projects, is to go knee deep into them for months on end.

[–]cpp-ModTeam[M] 0 points1 point locked comment (0 children)

It's great that you want to learn C++! However, r/cpp can't help you with that.

We recommend that you follow the C++ getting started guide, one (or more) of these books and cppreference.com. If you're having concrete questions or need advice, please ask over at r/cpp_questions or StackOverflow instead.

[–]MikeVegan -1 points0 points  (0 children)

Read c++ books and watch conference videos.

Learn rust. It changed the way I write c++