Bereitstellung von Einschränkungen für ein ParameterpaketC++

Programme in C++. Entwicklerforum
Anonymous
 Bereitstellung von Einschränkungen für ein Parameterpaket

Post by Anonymous »

Ich habe eine Vorlagenklasse, die ein Tupel enthält. < /p>

Code: Select all

template 
class Foo
{ ... };
< /code>
Wie kann ich eine Einschränkung auf die Typen in der Parameterpackung des Parameters anwenden?template < template class... SomeTypes>
class Bar
{ ... };
< /code>
-Bearbeiten-< /p>
Hier ist ein spezifischerer Fall von dem, wonach ich suche.  Der Code wird nicht kompiliert, da FOOB nicht kopierbar ist (dies wird erwartet).  Leider gibt der Compiler nicht die besten Fehlermeldungen an, wenn er in diesem Bereich ausgeführt wird (im tatsächlichen Code, den ich mit den Typen zu tun habe, sind komplexer und dies endet mit riesigen Fehlerromanen).  Ich hoffe, ich könnte Foocontainer eine Klausel hinzufügen, die einen viel klareren Fehler ergibt. < /P>
#include 
#include 

template 
class Foo
{
};

template 
class FooA : public Foo
{
public:
int some_data {0};

void DoSomething()
{
some_data++;
}
};

template 
class FooB : public Foo
{
public:
// non-copyable object
FooB() = default;
FooB( const FooB& ) = delete;
FooB& operator=( const FooB& ) = delete;
~FooB() = default;

int some_data {0};

void DoSomething()
{
some_data++;
}
};

template < template class... SomeTypes>
// requires (std::copyable) ???
class FooContainer
{
public:
std::tuple my_tuple;

template 
void DoAllThings()
{
}

template 
void DoAllThings()
{
std::get(my_tuple).DoSomething();
DoAllThings();
}
};

using MyContainer = FooContainer;

int main()
{
MyContainer my_bar;
my_bar.DoAllThings();
MyContainer my_bar2 = my_bar;
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post