1 /+ dub.sdl:
2     name "composer_examples_assert_messages"
3     dependency "composer" path="../"
4     targetType "executable"
5 +/
6 module examples.assert_messages;
7 
8 import composer.composer;
9 
10 private char[1024 * 4] msgBuffer;
11 
12 /**
13 Creates a thread-local composer, that will be destroyed
14 automatically when it's exceeded its useful lifespan.
15 
16 Because of thread-local storage, there is only one point
17 of access to the message buffer. This is best used when
18 there is a need to compose assert messages at runtime in
19 methods that must not allocate memory.
20 */
21 @property auto getComposer()
22 {
23     return Composer!char(msgBuffer[]);
24 }
25 
26 void main()
27 {
28     func();
29 }
30 
31 @safe @nogc func() nothrow
32 {
33     //dfmt off
34     assert(false, getComposer.write("This is a message with numbers: ", 12,
35                                  ", and pointers: ", ()@trusted {return cast(void*) 0xDEADBEEF;}())
36                              .message);
37     //dmft on
38 }