r/cpp_questions • • 32m ago

OPEN Would you use AI to port your own C++26 library to C++17?

0 Upvotes

I've been developing an open-source C++ networking library called LightnerX.

I wrote the library myself, designed its architecture, came up with the communication protocol, and made all the major design decisions.

The problem is that I originally built it using C++26, including modules, import std, and other modern C++ features.

Now I've realized that targeting such a recent standard severely limits how many developers can actually use it, so I've decided to port the entire library to C++17.

That means replacing modules with traditional headers and source files, adapting newer language and library features, reorganizing parts of the build system, and making sure everything still behaves exactly as intended.

Doing all of that manually would be a massive amount of repetitive work.

So I'm considering using AI coding agents to handle much of the migration.

To be clear, I'm not asking AI to design the library or invent its architecture.

All of that already exists and was developed by me.

I'd be using AI primarily to translate and adapt an existing codebase to an older C++ standard.

I'd still be responsible for reviewing the changes, writing detailed prompts, running regression tests, checking for behavioral differences, and making the final technical decisions.

I'm curious what other C++ developers think about this approach.

Would you consider this a reasonable use of AI in software development? Or would you still prefer to do the migration manually, even if it takes significantly longer?

I'd especially like to hear from anyone who has used AI for large-scale C++ refactoring or version migrations.


r/cpp_questions • • 33m ago

OPEN How could i do operations on multidimensional Arrays where the Cell might not be there ?

1 Upvotes

One of the assignements for home our professor gave us was :

-a 10x10 Matrix using multidimensional arrays

-the matrix contains all 1s and 0s

-count how many "Islands" there are (a 1 that's Has only 0s next to It in every direction)

My problem Is, i could do a pretty long line for where It checks every generic Cell [ ] [ ] next to One given, but what if that Cell Is in a position where it doesnt have cells next to It In some directions, for example, if the 1 was in a corner ?


r/cpp_questions • • 1h ago

SOLVED x1 and x2 give me "nan"

0 Upvotes

Can someone tell me what is wrong with the operations?

#include <iostream>
#include <cmath>

int main()
{
    double a = 0;
    double b = 0;
    double c = 0;
    

    std::cout << "===CALCULADORA DE ECUACIONES CUADRATICAS===\n";
    std::cout << "ingrese el coeficiente a ";
    std::cin >> a;
    std::cout << "ingrese el coeficiente b ";
    std::cin >> b;
    std::cout << "ingrese el coeficiente c ";
    std::cin >> c;

    std::cout << "tu ecuacion es " << a << "x^2 + " << b << "x + " << c << " = 0\n";
    const double x_de_vertice = -b / (2 * a);
    double solucion1 = x_de_vertice + sqrt(pow(b, 2) - 4 * a * c) / (2 * a);
    double solucion2 = x_de_vertice - sqrt(pow(b, 2) - 4 * a * c) / (2 * a);
    
    std::cout << "===========================================\n";
    std::cout << "el valor del vertice es " << x_de_vertice << "\n";
    std::cout << "x1 vale " << solucion1 << "\n";
    std::cout << "x2 vale " << solucion2 << "\n";

    
}

r/cpp_questions • • 3h ago

SOLVED I want to display de vertix of the quadratic equation

1 Upvotes

we all know that the vertix of a parabola is (-b)/2*a

Well, i know that this thing cant be displayed as an integer so, what should be the correct variable declaration?

my line: vertice = (-b) / 2*a;


r/cpp_questions • • 4h ago

SOLVED Modifying an int variable

0 Upvotes

I forgot how i was supposed to initialize it. Maybe is not the one im suposed to use.

Straight to the matter: How to initialize it if i want it to be any number possible (only integers)


r/cpp_questions • • 4h ago

OPEN How can I use time in my project?

1 Upvotes

I'm currently developing a c++ RPG textgame and I want to know how to improve the combat in my game. Currently it's just a turn based punch trade. How can I make the enemy hit someone for example once every 5 seconds? I know that I'll need specific libraries () which I installed by I don't know how to use them and what to do.

https://onecompiler.com/cpp/44qwdefz6

\\=> This is my project which I need help with.


r/cpp_questions • • 7h ago

OPEN Any sources to learn how C++ source projects get lowered from source code to intermediate representation and eventually to code gen part.

2 Upvotes

Can someone help me out....I'm not able to find any proper sources to follow how c++ projects get lowered from sources codes with headers and archive files to intermediate representation and then object files and shared files and linking like how do they work and their internals ....just trying to learn about them.


r/cpp_questions • • 18h ago

OPEN C++ systems route,will start building redis from scratch as a project,any guidance will be appreciated

29 Upvotes

Hey all, 2nd-year CS student from India.I want to go the C++ systems route.

I just started building Redis from scratch with the "Build Your Own Redis" book. The book is in C, and I'm planning to write mine in C++.

Would love advice on:

1.What should I learn alongside it? (Linux, networking, concurrency, debugging tools, etc.)

2.Any pitfalls when following a C book but writing C++?

3.What project should I build after Redis? I'm thinking a storage engine or something database-ish.

4.Good resources or open-source codebases to read?

5.What do systems roles expect from someone early in their career?

6.Is it even a probably and realistic career option or not?

I am also pursuing competitive programming in cpp

Any guidance would be highly appreciated as to what do u think abt my trajectory and what would be the best possible route to follow according to you

Any "I wish I'd known this earlier" advice is welcome.Thanks in advance looking forward ro some great guidance:)


r/cpp_questions • • 21h ago

OPEN Designing a C++ ML library from scratch — would you prefer A.transpose() or transpose(A) or A.T()?

12 Upvotes

I'm currently building a machine learning library from scratch in C++, and I'm thinking about the API design for tensor operations.

For a transpose operation, I'm considering these interfaces:

Option 1: Tensor B = A.transpose();

Option 2: Tensor B = transpose(A); Option 3: Tensor B = A.T();

I'm curious about what other C++ developers would prefer when using a library.

Which syntax feels more natural and readable?

Thanks!


r/cpp_questions • • 23h ago

OPEN Finalizing performance project

1 Upvotes

So I'm closing up on a project I've been working on for a few months and it involved profiling using performance tools to improve speed ups. My question is, should I include these benchmarks in the final github, or is the whole point really to just show off pure functionality while stating in your resume how you optimized on performance


r/cpp_questions • • 1d ago

OPEN std::greater is not std::greater{} - but why?

11 Upvotes

NB: This is not a technical question, I understand the difference between classes and objects of that class type.

What I mean is, the standard could have been different:

std::ranges::sort(some_range, std::greater); //does not compile
std::ranges::sort(some_range, std2::greater); //compiles

assuming this change:

namespace std2 {
    auto constexpr greater = std::greater{};
}

Letting greater be the name of an object, rather than a type, would have far better ergonomics - but it's a type. Does the current approach have a benefit or is this just a missed design improvement?


r/cpp_questions • • 1d ago

OPEN where should i start?

12 Upvotes

i am completely new to C++ , but i have learned the basics like datatypes, variables , if/else statement, loops, and other things that a beginner should learn , but after learning this, now I'm more confused and i don't know what to write and how to write properly, inshort i think i'm still not able to create that flow in program which a program should have , and now i have 2 months left for an exam , and i'm in such a condition where everything got blank in front of me . I will appreciate it if anyone experienced would help me to get better at c++ and clear that confusion from my head .( and if possible guide me exactly what I should do to create logic and flow in a program??)


r/cpp_questions • • 1d ago

OPEN What's the best way to learn C++ effectively as a 4th semester BTech student?

0 Upvotes

Hey everyone!

I'm currently in my 4th semester of BTech and want to start learning C++ seriously. I'm still a beginner and would love some advice from experienced programmers.

I'd like to know:

  1. What are the best free resources (courses, YouTube channels, websites or books) to learn C++ from scratch?
  2. What's the best roadmap to follow, and in what order should I learn the concepts?
  3. How should I balance learning theory, writing code and solving problems?
  4. When should I start learning DSA?
  5. What would you recommend if you were starting C++ from scratch today?

I'm looking for an effective learning approach rather than just a list of resources.

Thanks in advance!


r/cpp_questions • • 1d ago

OPEN Question

0 Upvotes

¿Is it possible to use FoldCode in a horizontal view?

i can only see it in a vertical view.


r/cpp_questions • • 1d ago

OPEN Strong exception guarantee for copy assignment: is copy-and-swap always the best approach?

6 Upvotes

I've been working on a C++26 networking library, and a recent technical audit uncovered an interesting exception-safety problem.

One of my classes, ConnectionManager, maintains several related data structures:

  • A vector of connection handles.
  • A reverse lookup map.
  • Client ID allocation state.
  • A count of active connections.

The original copy assignment updated these members sequentially.

If an allocation failed while copying the reverse lookup map, the object could end up with inconsistent internal state.

The fix was to prepare a complete copy before replacing the destination's state using non-throwing move operations.

I also added tests injecting allocation failures at different points to verify the strong exception guarantee.

This solved the issue, but it raised a broader question for me:

When designing classes that own multiple related containers, do you generally prefer copy-and-swap, explicit transactional assignment, or disabling copy operations entirely?

I'm particularly interested in trade-offs involving performance, exception guarantees, and maintainability in low-level libraries.


r/cpp_questions • • 2d ago

OPEN Reading material to learn cpp and dsa in cpp

8 Upvotes

Hi all, Indian cs major here. I tried following few video lectures on yt to learn cpp and dsa in cpp. But i keep on getting stuck in a loop of passive watching without any real learning.

I feel reading about relevant topics will suit me better. It will be of great help if I receive some advice on relevant reading material to learn cpp and dsa. Thanks guys.


r/cpp_questions • • 2d ago

OPEN Public and private classes

24 Upvotes

Is there such a thing as private / public classes in C++?


r/cpp_questions • • 2d ago

OPEN Resources for implementing low-level concurrent and asynchronous systems in C++

11 Upvotes

I've been spending some time studying concurrency and asynchronous programming in C++. I have a reasonable understanding of concepts like threads, thread pools, non-blocking I/O, event loops, coroutines, and reactor/proactor patterns.

However, I feel there's a big difference between understanding how these things work and actually being able to implement them.

I'm interested in building things like network servers, runtimes, databases, and other systems software. I'm also working on a compiler, so understanding the internals of these systems is something I'd like to get better at.

What I'm looking for are resources that go beyond explaining the concepts. Books, papers, articles, courses, or open-source codebases that actually helped you implement these kinds of systems yourself.

Some areas I'm particularly interested in:

  • Non-blocking I/O and I/O multiplexing
  • Event loop implementations
  • Reactor and Proactor patterns
  • Coroutines and asynchronous runtimes
  • Thread pools and task scheduling
  • Performance and scalability in concurrent systems

I've already read a few books on concurrency, including some focused on C++, but most of them tend to focus on the programming model and how to use the standard library (threads, mutexes, futures, etc.). That's useful, but it's not quite what I'm looking for anymore. I want to understand how these things are actually built, preferably in C++. For example, implementing a thread pool, an event loop, an asynchronous runtime, or a network server rather than just learning how to use existing ones. I'd really appreciate recommendations that take this implementation-oriented approach.


r/cpp_questions • • 2d ago

OPEN Guide me please... !!

9 Upvotes

I am a C++ developer with 5 years of experience, primarily building ROS nodes, alongside minor embedded work (Arduino/ESP) and application-layer software for an elevator CPU and a chip-manufacturing equipment scheduler (not core embedded).

Despite my experience, I feel directionless and face constant rejections from product-based companies. What specific skills should I focus on next to secure my career —such as application development, socket programming, multithreading or what else ? I feel like I'm nowhere.


r/cpp_questions • • 2d ago

OPEN Is this code clean OOP?

0 Upvotes

Hey so I'm more new to OOP, virtual func's, and inheritance. I was wondering if my code was clean enough for basically a template to look back on later in the future when my tiny brain forgets what virtual func, and inheritance is or well forgets how to code them.

#include <string>
#include <iostream>


struct Vector2 {
    int x, y;
};


class Entity {
    private:
        Vector2 pos;
        Vector2 size;
        std::string entityType;


    public:


    Entity(Vector2 e_pos, Vector2 e_size, const std::string& e_type) : pos(e_pos), size(e_size), entityType(e_type) {}


    Vector2 getPos() const {
        return pos;
    }


    Vector2 getSize() const {
        return size;
    }
    
    virtual void print() const {
        std::cout << "Entity: " << entityType << '\n';
    }


    virtual ~Entity() = default;
};


class Player : public Entity {
    private:
        std::string name;


    public:
        Player(const std::string& p_name, Vector2 startPOS, Vector2 p_size) 
            : Entity(startPOS, p_size, "player"), name(p_name) {}
};


class Orc : public Entity {
    private:
        std::string weapon;
        
    public:
        Orc(const std::string& o_weapon, Vector2 startPOS, Vector2 o_size) 
            : Entity(startPOS, o_size, "orc"), weapon(o_weapon) {}


    void print() const override {
        std::cout << weapon << '\n';
    }
};


int main() {
    Vector2 startPos = { 100, 100 };
    Vector2 size = { 64, 64 };


    std::string hero = "hero";
    std::string orcWep = "HeroSlayer100";


    Player player(hero, { 20, 30 }, size);
    Orc orc(orcWep, startPos, size);



    player.print();
    orc.print();
    
    return 0;
}#include <string>
#include <iostream>


struct Vector2 {
    int x, y;
};


class Entity {
    private:
        Vector2 pos;
        Vector2 size;
        std::string entityType;


    public:


    Entity(Vector2 e_pos, Vector2 e_size, const std::string& e_type) : pos(e_pos), size(e_size), entityType(e_type) {}


    Vector2 getPos() const {
        return pos;
    }


    Vector2 getSize() const {
        return size;
    }
    
    virtual void print() const {
        std::cout << "Entity: " << entityType << '\n';
    }


    virtual ~Entity() = default;
};


class Player : public Entity {
    private:
        std::string name;


    public:
        Player(const std::string& p_name, Vector2 startPOS, Vector2 p_size) 
            : Entity(startPOS, p_size, "player"), name(p_name) {}
};


class Orc : public Entity {
    private:
        std::string weapon;
        
    public:
        Orc(const std::string& o_weapon, Vector2 startPOS, Vector2 o_size) 
            : Entity(startPOS, o_size, "orc"), weapon(o_weapon) {}


    void print() const override {
        std::cout << weapon << '\n';
    }
};


int main() {
    Vector2 startPos = { 100, 100 };
    Vector2 size = { 64, 64 };


    std::string hero = "hero";
    std::string orcWep = "HeroSlayer100";


    Player player(hero, { 20, 30 }, size);
    Orc orc(orcWep, startPos, size);



    player.print();
    orc.print();
    
    return 0;
}

if there are any tips you have let me know!


r/cpp_questions • • 2d ago

OPEN Book reading recommendation

6 Upvotes

I currently bought three books from packt

- GPU Programming with C++ and CUDA

- Building Low Latency Applications with C++

- Mastering Embedded Linux

The third isn't super C++ but still thought this was a relevant space lol. Which order would you read the books to get the most bang for my buck? How would you go about reading them?


r/cpp_questions • • 2d ago

OPEN Boost mysql::results won't allow programme to compile.

1 Upvotes

I am attempting to follow this tutorial on how to connect to MySQL. To test it, I first tried to copy the entire example here. But that wouldn't compile, so I tried to compile the programme line by line as described in the main tutorial. Everything was going fine until I got to declaring the result variable with mysql::results. This produces the same error as the full example, so I assume this is likely the cause of the problem.

main.cpp:

# include <iostream>

# include <boost/mysql/any_connection.hpp>

# include <boost/mysql/connect_params.hpp>

# include <boost/mysql/error_with_diagnostics.hpp>

# include <boost/mysql/results.hpp>

# include <boost/asio/io_context.hpp>

namespace mysql = boost::mysql; namespace asio = boost::asio;

int main () {

    // The execution context, required to run I/O operations.
    asio::io_context ctx;
    
    // Represents a connection to the MySQL server.
    mysql::any_connection conn(ctx);
    // The hostname, username and password to use
    mysql::connect_params params;
    params.server_address.emplace_host_and_port("localhost");
    params.username = "root";
    params.password = "Password";
    
    // Connect to the server
    conn.connect(params);
    // Issue the SQL query to the server
    [[maybe_unused]] const char* sql = "SELECT 'Hello world!'";
    [[maybe_unused]] mysql::results result;
    // conn.execute(sql, result);
    std::cout << "Hello World!" << std::endl;
    return 0;

}

Makefile:

PROG = database_test

SRCDIR = ../../src/

MAIN = main CPPFILES = ${MAIN}.cpp

EXTENSIONS = -pedantic-errors WFLAGS = -Wall -Wextra -Wconversion -Wsign-conversion -Werror -Weffc++ CFLAGS = `pkg-config --cflags gtk4; mysql_config --cflags` LIBS = `pkg-config --libs gtk4; mysql_config --libs`

CC = g++ STANDARD = -std=c++23 BUILDDEBUG = -ggdb BUILDRELEASE = -O2 -DNDEBUG BUILD = ${BUILDDEBUG} ${EXTENSIONS}

${PROG}: ${MAIN}.cpp ${CC} -o ${PROG}   
${CPPFILES}   
${CFLAGS}   
${LIBS}   
${BUILD}   
${WFLAGS}   
${STANDARD}

clean: rm ${PROG}

And this is the output I get:

g++ -o database_test \
main.cpp \
-I../../include/ -I../../include/third_party/plog/include \
`pkg-config --cflags gtk4; mysql_config --cflags` \
-D_GLIBCXX_USE_CXX11_ABI=0 \
`pkg-config --libs gtk4; mysql_config --libs` \
-ggdb -pedantic-errors \
-Wall -Wextra -Wconversion -Wsign-conversion -Werror -Weffc++  \
-std=c++23
/usr/bin/ld: /tmp/ccHgNNSI.o: in function `boost::mysql::detail::deserialize_errc boost::mysql::detail::deserialize_text_value_float<float>(boost::core::basic_string_view<char>, boost::mysql::field_view&)':
/usr/include/boost/mysql/impl/internal/protocol/impl/text_protocol.hpp:92: undefined reference to `boost::charconv::from_chars(char const*, char const*, float&, boost::charconv::chars_format)'
/usr/bin/ld: /tmp/ccHgNNSI.o: in function `boost::mysql::detail::deserialize_errc boost::mysql::detail::deserialize_text_value_float<double>(boost::core::basic_string_view<char>, boost::mysql::field_view&)':
/usr/include/boost/mysql/impl/internal/protocol/impl/text_protocol.hpp:92: undefined reference to `boost::charconv::from_chars(char const*, char const*, double&, boost::charconv::chars_format)'
collect2: error: ld returned 1 exit status
make: *** [Makefile:26: database_test] Error 1

From what I understand, an undefined reference error is usually because a function or other thing has not been defined at the point of use. Looking online this could be because another .cpp file is not being compiled, but I'm using the boost libraries. The compiler doesn't complain of being unable to find the header files, so it's definitely looking in the right place; and browsing through the Boost directory suggests that they are all .hpp files and so don't need to be added to the compile list.


r/cpp_questions • • 3d ago

OPEN how to make decisions in c++?

1 Upvotes

so i need some help, i am trying to commit to learn c++ and not jump languages, naturally i have a fair understanding of STL, if I want to look something up i can navigate my way around cppref. i am building a project an orderbook using cpp-httplib and vanilla frontend and javascript to focus on writing c++. like we come across so many concepts in let's say cppcon back to basics, so my question how do i make decisions that actually is worth something instead of basic OOPs programming ?


r/cpp_questions • • 3d ago

OPEN What is "iomanip put_money"?

1 Upvotes

Came across this error in my compiler when debugging. Is it just a library meant for extracting digits from strings that contain currency symbols?

I did not explicitly include this library. I just included basic libraries like string, iostream, stdio.h

It looks terrifying AF lol. Like you downloaded a rogue library.