text
stringlengths 0
2.2M
|
---|
const native_std::type_index index = info;
|
ASSERT(info.hash_code() == index.hash_code());
|
}
|
#endif
|
static const bool u_BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY_defined =
|
#if defined(BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY)
|
true;
|
#else
|
false;
|
#endif
|
// case 1
|
#if defined(BSLS_LIBRARYFEATURES_HAS_CPP98_AUTO_PTR) ||\
|
defined(BSLS_LIBRARYFEATURES_HAS_CPP98_AUTO_PTR_FORCE)
|
#include <memory>
|
native_std::auto_ptr<int> ap;
|
#endif
|
static const bool u_BSLS_LIBRARYFEATURES_HAS_CPP98_AUTO_PTR_defined =
|
#if defined(BSLS_LIBRARYFEATURES_HAS_CPP98_AUTO_PTR)
|
true;
|
#else
|
false;
|
#endif
|
using namespace BloombergLP;
|
// ============================================================================
|
// USAGE EXAMPLE
|
// ----------------------------------------------------------------------------
|
///Usage
|
///-----
|
// In this section we show intended usage of this component.
|
//
|
///Example 1: Managing Library-Dependent Interfaces
|
/// - - - - - - - - - - - - - - - - - - - - - - - -
|
// When building software across multiple platforms may have to deal with
|
// different versions of the native standard library, some providing features
|
// that the others do not. The macros defined in this component can be used
|
// make features visible only if the required native standard library features
|
// are present.
|
//
|
// For example, the 'tuple'-type is not available in older versions of the
|
// native standard library. Suppose we have a utility component that returns
|
// an instance of a 'tuple' of values *if* the underlying version of the
|
// standard library provides that type, and yet remain compilable otherwise.
|
//
|
// First, we conditionally include the header file we will need if we define an
|
// interface that returns a 'native_std::tuple'.
|
//..
|
#if defined(BSLS_LIBRARYFEATURES_HAS_CPP11_TUPLE)
|
# ifndef INCLUDED_TUPLE
|
# include <tuple>
|
# define INCLUDED_TUPLE
|
# endif
|
#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_TUPLE
|
//..
|
// Then, we declare the methods that will be unconditionally provided by our
|
// utility component:
|
//..
|
struct MyStatisticalUtil
|
{
|
static double mean(const int *begin, const int *end);
|
static int median(const int *begin, const int *end);
|
static double variance(const int *begin, const int *end);
|
// Return the median (mean, variance) of the sequence of values in
|
// the specified non-empty, semi-open range '[begin, end)'. The
|
// behavior is undefined unless 'begin < end'.
|
//..
|
// Now, we conditionally define an interface that returns a 'bsl::type', if
|
// that type is available. Note that, if all three values are needed, calling
|
// this interface is more efficient than calling the earlier three individually
|
// because the input need be traversed one time, not three.
|
//..
|
#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_TUPLE
|
static native_std::tuple<int, double, double> getMedianMeanVariance(
|
const int *begin,
|
const int *end);
|
// Return the median, mean, and variance (in that order) of the
|
// sequence of values in the specified non-empty, semi-open range
|
// '[begin, end)'. The behavior is undefined unless 'begin < end'.
|
#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_TUPLE
|
};
|
//..
|
// Finally, we find that our code compiles when we build our code against
|
// versions of the native standard library that provide a 'tuple' type, *and*
|
// those that do not. Of course, in the later case the interface that returns
|
// a 'tuple' is not defined for the 'MyStatisticalUtil' 'struct'.
|
// ============================================================================
|
// HELPER FUNCTIONS
|
// ----------------------------------------------------------------------------
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.