You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
-
You may be looking for C++20 "concepts", which lets you constrain template parameters. Someone posted a great answer here to that effect, but then deleted it :( Another pattern I've seen is a "trait" template that wraps an implementation with an uniform interface – somewhat like pimpl but without the encapsulation or type erasure. But in simple cases you can just define an abstract base class from which all implementations shall inherit.amon– amon2023-12-13 22:11:42 +00:00Commented Dec 13, 2023 at 22:11
-
1The concept answer is indeed good, it just needed modification to remove the template usage. Instead, the Mutex.hpp should include portable/Mutex.hpp and afterwards do a static_assert that the defined mutex class satisfies the concept.Sebastian Redl– Sebastian Redl2023-12-14 08:32:33 +00:00Commented Dec 14, 2023 at 8:32
-
1However, I think OP is overthinking this issue. The platform-specific implementations aren't user extension points where you have to be paranoid about correctness. Presumably, any such code would still be in the main repository, reviewed by the original author, and compiled at least every now and then. You get lots of compile errors, you need to fix the implementation.Sebastian Redl– Sebastian Redl2023-12-14 08:34:24 +00:00Commented Dec 14, 2023 at 8:34
-
"not suitable for applications which do no/should not use the heap" You can use placement new to have the pimpl be a subobject of the enclosing class, although that might remove the ABI compatibilityCaleth– Caleth2023-12-14 09:21:30 +00:00Commented Dec 14, 2023 at 9:21
-
@Caleth I had toyed with this idea in the past using memory pools (i.e., placement new). However, I'm not sure how you overcome the fact that the memory in which to perform the placement new still needs a size which you can't know exactly unless you have the declaration of the implementation.Patrick Wright– Patrick Wright2023-12-14 15:27:29 +00:00Commented Dec 14, 2023 at 15:27
|
Show 1 more comment
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
-
create code fences with backticks ` or tildes ~
```
like so
``` -
add language identifier to highlight code
```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible)
<https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. design-patterns), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
lang-cpp