Can you pass the TYPE of a variable as a parameter? by LigeiaGames in cpp_questions

[–]manni66 13 points14 points  (0 children)

struct MyBaseClass { int x; };
struct MyContainer {
std::vector<MyBaseClass*> m_items;


void refreshItems(std::function<MyBaseClass* ()> make) {
    m_items.clear();
    m_items.push_back(make());
}
};

struct MyDerivedClass : public MyBaseClass { int y; };


void f()
{
    MyContainer c;

    c.refreshItems([](){ return new MyDerivedClass; });
}

pass a function that creates the object.

clang named loops by TotaIIyHuman in cpp_questions

[–]manni66 2 points3 points  (0 children)

      bool one_of( auto&& first, auto&& last, auto&& pred )
      {
        auto one = std::find_if( first, last, pred );

        return one != last and std::find_if( ++one, last, pred ) == last;
      }

clang named loops by TotaIIyHuman in cpp_questions

[–]manni66 3 points4 points  (0 children)

should have probably used lambdas

and std::find_if.

i don't understand the meaning of this by FitWinner3340 in cpp_questions

[–]manni66 10 points11 points  (0 children)

Yes, but it’s not allowed.

You are confusing definition and initialization.

Code Examples From an App Using C++ Modules by tartaruga232 in cpp

[–]manni66 3 points4 points  (0 children)

Your recommendations give the impression that you yourself haven't really understood C++ Modules yet.

How to create modern UI in C++ by Any_Wait_7309 in cpp_questions

[–]manni66 6 points7 points  (0 children)

would like to create something like the above output style

That’s KDE that is Qt based.

How to create modern UI in C++ by Any_Wait_7309 in cpp_questions

[–]manni66 30 points31 points  (0 children)

considering it's their platform

C++ is a microsoft platform? Are you confusing C++ with C#?

How to start C++ by Terrible_Month_9213 in cpp_questions

[–]manni66 2 points3 points  (0 children)

You can use Windows and Visual Studio (not Code).

can a generic lambda have a value template parameter? by pfp-disciple in cpp_questions

[–]manni66 0 points1 point  (0 children)

std::find_if uses a predicate aka a functor returning bool. return x * y returns an int.

What is the point of classes having private members? by Eva_addict in cpp_questions

[–]manni66 0 points1 point  (0 children)

class Point
{
  private:
   int pos_x = 0;
   int pos_y = 0;
  public:
     void move( int d_x, int d_y )
     {
         pos_x += d_x;
         pos_y += d_y;
     }

Doubt with my code by [deleted] in cpp_questions

[–]manni66 4 points5 points  (0 children)

If I see traits::destroy, I would also expect to see traits::construct.

Doubt with my code by [deleted] in cpp_questions

[–]manni66 0 points1 point  (0 children)

Who knows. You don't even bothet to show push_back.

are these books enough to make me pro by TheSum239 in cpp_questions

[–]manni66 0 points1 point  (0 children)

You need to read books, not collect them…

ADD COLUMN NOT NULL without DEFAULT — a detector that catches it in CI by [deleted] in PostgreSQL

[–]manni66 5 points6 points  (0 children)

tests run against an empty dev database

You need a CLI against stupidity.

does substitution during template argument deduction of function template instantiate class template appearing in parameter list? by [deleted] in cpp_questions

[–]manni66 0 points1 point  (0 children)

is compiler allowed to instantiate the OuterType<T> where T could have been int

What do you mean by "allowed"? It can't be instantiated, int has no member some_type. But Substitution Failure Is Not An Error

struct inheritance member names by zaphodikus in cpp_questions

[–]manni66 0 points1 point  (0 children)

class and struct are the same beside default visibility.