text stringlengths 0 2.2M |
|---|
bslma::Allocator *basicAllocator)
|
: d_value(bslma::ConstructionUtil::make<TYPE>(basicAllocator,
|
other.value()))
|
, d_listener(other.d_listener)
|
{
|
}
|
//..
|
// Note that, in order for 'd_value' to be constructed with the correct
|
// allocator, the compiler must construct the result returned by 'make'
|
// directly into the 'd_value' variable, an optimization formerly known prior
|
// to C++17 as "copy elision". This optimization is required by the C++17
|
// standard and is optional in pre-2017 standards, but is implemented in all
|
// of the compilers for which this component is expected to be used at
|
// Bloomberg.
|
//
|
// Next, we implement the assignment operators, which simply call 'setValue':
|
//..
|
template <class TYPE, class FUNC>
|
MyTriggeredWrapper<TYPE, FUNC>&
|
MyTriggeredWrapper<TYPE, FUNC>::operator=(const TYPE& rhs)
|
{
|
setValue(rhs);
|
return *this;
|
}
|
template <class TYPE, class FUNC>
|
MyTriggeredWrapper<TYPE, FUNC>&
|
MyTriggeredWrapper<TYPE, FUNC>::operator=(const MyTriggeredWrapper& rhs)
|
{
|
setValue(rhs.value());
|
return *this;
|
}
|
//..
|
// Then, we implement 'setValue', which calls the listener after modifying the
|
// value:
|
//..
|
template <class TYPE, class FUNC>
|
void MyTriggeredWrapper<TYPE, FUNC>::setValue(const TYPE& value)
|
{
|
d_value = value;
|
d_listener(d_value);
|
}
|
//..
|
// Finally, we check our work by creating a listener for 'MyContainer<int>'
|
// that stores its last-seen value in a known location and a wrapper around
|
// 'MyContainer<int>' to test it:
|
//..
|
int lastSeen = 0;
|
void myListener(const MyContainer<int>& c)
|
{
|
lastSeen = c.front();
|
}
|
void usageExample3()
|
{
|
bslma::TestAllocator testAlloc;
|
MyTriggeredWrapper<MyContainer<int>,
|
void (*)(const MyContainer<int>&)>
|
wrappedContainer(myListener, &testAlloc);
|
ASSERT(&testAlloc == wrappedContainer.value().allocator());
|
wrappedContainer = MyContainer<int>(99);
|
ASSERT(99 == lastSeen);
|
}
|
//..
|
#endif // defined(BSLS_COMPILERFEATURES_GUARANTEED_COPY_ELISION)
|
//=============================================================================
|
// MAIN PROGRAM
|
//-----------------------------------------------------------------------------
|
int main(int argc, char *argv[])
|
{
|
int test = argc > 1 ? atoi(argv[1]) : 0;
|
verbose = argc > 2;
|
veryVerbose = argc > 3;
|
veryVeryVerbose = argc > 4;
|
veryVeryVeryVerbose = argc > 5;
|
forceDestructorCall = veryVeryVerbose;
|
bslma::TestAllocator defaultAllocator("default", veryVeryVeryVerbose);
|
bslma::DefaultAllocatorGuard dag(&defaultAllocator);
|
bslma::TestAllocator globalAllocator("global", veryVeryVeryVerbose);
|
bslma::Default::setGlobalAllocator(&globalAllocator);
|
setbuf(stdout, NULL); // Use unbuffered output
|
printf("TEST " __FILE__ " CASE %d\n", test);
|
switch (test) { case 0: // Zero is always the leading case.
|
case 12: {
|
// --------------------------------------------------------------------
|
// USAGE EXAMPLE
|
//
|
// Concerns:
|
//: 1 The usage example provided in the component header file compiles,
|
//: links, and runs as shown.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.