forked from mockingbirdnest/Principia
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A macro to check that some constructs are ill-formed.
- Loading branch information
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
#include <type_traits> | ||
|
||
#define PRINCIPIA_CONCATENATE(s1, s2) s1##s2 | ||
#define PRINCIPIA_CONCATENATE_EXPANSION(s1, s2) PRINCIPIA_CONCATENATE(s1, s2) | ||
|
||
#define PRINCIPIA_CHECK_WELL_FORMEDNESS(unique_concept_name, \ | ||
expected_well_formedness, \ | ||
expected_well_formedness_description, \ | ||
expression, \ | ||
...) \ | ||
template<template<typename> typename WITH = std::type_identity_t> \ | ||
concept unique_concept_name = \ | ||
requires(__VA_ARGS__) { \ | ||
(expression); \ | ||
}; \ | ||
static_assert(expected_well_formedness unique_concept_name<>, \ | ||
"Expected\n " #expression \ | ||
"\n" expected_well_formedness_description) | ||
#define PRINCIPIA_CHECK_ILL_FORMED(expression, ...) \ | ||
PRINCIPIA_CHECK_WELL_FORMEDNESS( \ | ||
PRINCIPIA_CONCATENATE_EXPANSION(test_concept_, __COUNTER__), \ | ||
!, \ | ||
"not to compile", \ | ||
expression, \ | ||
__VA_ARGS__) | ||
#define PRINCIPIA_CHECK_WELL_FORMED(expression, ...) \ | ||
PRINCIPIA_CHECK_WELL_FORMEDNESS( \ | ||
PRINCIPIA_CONCATENATE_EXPANSION(test_concept_, __COUNTER__), \ | ||
, \ | ||
"to compile", \ | ||
expression, \ | ||
__VA_ARGS__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "testing_utilities/check_well_formedness.hpp" | ||
|
||
#include <string> | ||
|
||
PRINCIPIA_CHECK_ILL_FORMED(s + 3, WITH<std::string> s); | ||
PRINCIPIA_CHECK_ILL_FORMED(s + "3", WITH<std::pair<double, double>> s); | ||
PRINCIPIA_CHECK_WELL_FORMED(s + t, WITH<std::string> s, WITH<std::string> t); | ||
PRINCIPIA_CHECK_ILL_FORMED(s - t, WITH<std::string> s, WITH<std::string> t); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters