Hey guys.
I have been using concepts for some time and they work very well. Now I'd like to add module support.
The important part here: I need to be backwards compatible (i.e. use classic includes and imports side by side in different build configurations)
I'm using latest MSVC with latest CMake.
One of my concepts looks like this
ITask.hpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#pragma once
#ifdef USE_CXX_MODULES
import std.compat;
#else
#include <concepts>
#endif //USE_CXX_MODULES
namespace ns
{
template < typename T >
concept ITask_T = requires(T a)
{
{ a.start() }->std::same_as<void>; ///< Starts the task
{ a.stop() } -> std::same_as<void>; ///< Stops the task
};
}
|
I can use this concept to pass ITask_T instead of a generic parameter to my templated classes.
One (simple) implementation could be
MyTask.hpp
1 2 3 4 5 6 7 8 9 10
|
#pragma once
namespace ns
{
class MyTask
{
public:
void start();
void stop();
};
}
|
My module looks like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
module;
#include <ITask.hpp>
#include <MyTask.hpp>
export module my_module;
export
{
namespace ns
{
using ::ns::MyTask;
}
}
|
However i haven't found a way to export my ITask conept as well.
If I mix include <ITask.hpp> and import my_module I run into name clashses for ITask.
I cannot move the concept into the module since I need to preserve backward compatibility. Does somebody know how to export concepts form modules?
Thx guys :)