Stroika Library
3.0d16
Help-Home
Loading...
Searching...
No Matches
ObjectForSideEffects.h
1
/*
2
* Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3
*/
4
#ifndef _Stroika_Foundation_Common_ObjectForSideEffects_h_
5
#define _Stroika_Foundation_Common_ObjectForSideEffects_h_ 1
6
7
#include "Stroika/Foundation/StroikaPreComp.h"
8
9
#include <functional>
10
11
#include "Stroika/Foundation/Common/Common.h"
12
13
namespace
Stroika::Foundation::Common
{
14
15
/**
16
* \todo - see if we can get template guides working and merge this into ObjectForSideEffects
17
* - with templated value for function object.
18
*/
19
class
EmptyObjectForSideEffects
{
20
public
:
21
/**
22
* \brief Sometimes you want to sequence some code around mem-initializers. SOMETIMES - if those mem-initializers take paraemters, you can
23
* squeeze this in with (fake-value-for-side-effect,real-value) arguments.
24
* But other times that doesn't work out, and this trick solves the same problem, perhaps more cleanly.
25
*
26
* \par Example Usage
27
* \code
28
* struct foo { ...
29
* // Mark the activity 'constructing WSAPI webserver' as surrounding the construction of the ConnectionManager object
30
* static constexpr Activity kContructing_WSAPI_WebServer_{L"constructing WSAPI webserver"sv};
31
* optional<DeclareActivity<Activity<wstring_view>>> fEstablishActivity1_{&kContructing_WSAPI_WebServer_};
32
* ConnectionManager fWSConnectionMgr_;
33
* [[no_unique_address]] EmptyObjectForSideEffects fIgnore1_{[this]() { fEstablishActivity1_.reset (); }};
34
* ...
35
* };
36
* \endcode
37
*/
38
template
<
typename
CONSTRUCTOR_CALL>
39
EmptyObjectForSideEffects
(CONSTRUCTOR_CALL&& ctorCall);
40
};
41
42
/**
43
*/
44
class
ObjectForSideEffects {
45
public
:
46
/**
47
* \brief Sometimes you want to sequence some code around mem-initializers. SOMETIMES - if those mem-initializers take paraemters, you can
48
* squeeze this in with (fake-value-for-side-effect,real-value) arguments.
49
* But other times that doesn't work out, and this trick solves the same problem, perhaps more cleanly.
50
*
51
* \par Example Usage
52
* \code
53
* struct foo { ...
54
* // Mark the activity 'constructing WSAPI webserver' as surrounding the construction of the ConnectionManager object
55
* static constexpr Activity kContructing_WSAPI_WebServer_{L"constructing WSAPI webserver"sv};
56
* optional<DeclareActivity<Activity<wstring_view>>> fEstablishActivity1_{&kContructing_WSAPI_WebServer_};
57
* ObjectForSideEffects fIgnore1_{[this]() { DbgTrace ("this far in construction mem-initializers"); }, []() { DbgTrace(L"destroying this far in mem initializers"); }};
58
* ConnectionManager fWSConnectionMgr_;
59
* ...
60
* };
61
* \endcode
62
*/
63
template
<
typename
CONSTRUCTOR_CALL,
typename
DESTRUCTOR_CALL>
64
ObjectForSideEffects (CONSTRUCTOR_CALL&& ctorCall, DESTRUCTOR_CALL&& dtorCall);
65
~ObjectForSideEffects ();
66
67
private
:
68
function<void ()> fDestructor_;
69
};
70
71
}
72
73
/*
74
********************************************************************************
75
***************************** Implementation Details ***************************
76
********************************************************************************
77
*/
78
#include "ObjectForSideEffects.inl"
79
80
#endif
/*_Stroika_Foundation_Common_ObjectForSideEffects_h_*/
Stroika::Foundation::Common::EmptyObjectForSideEffects
Definition
ObjectForSideEffects.h:19
Stroika::Foundation::Common
Definition
Character.inl:624
Library
Sources
Stroika
Foundation
Common
ObjectForSideEffects.h
Generated by
1.9.8