Macros | Functions
MetaUtils_test.cc File Reference

Unit test for some of the utilities in MetaUtils.h. More...

#include <boost/test/unit_test.hpp>
#include "larcorealg/CoreUtils/zip.h"
#include "larcorealg/CoreUtils/MetaUtils.h"
#include <array>
#include <string>
#include <string_view>
#include <memory>
#include <type_traits>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( MetaUtils_test )
 

Functions

void referenced_address_test ()
 
void referenced_addresser_documentation_test ()
 
void lvalue_reference_into_wrapper_test ()
 
 BOOST_AUTO_TEST_CASE (ReferencesTestCase)
 

Detailed Description

Unit test for some of the utilities in MetaUtils.h.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
March 22, 2019
See also
larcorealg/CoreUtils/MetaUtils.h

Definition in file MetaUtils_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( MetaUtils_test )

Definition at line 10 of file MetaUtils_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( ReferencesTestCase  )

Definition at line 354 of file MetaUtils_test.cc.

354  {
355 
359 
360 } // BOOST_AUTO_TEST_CASE(ReferencesTestCase)
void referenced_addresser_documentation_test()
void referenced_address_test()
void lvalue_reference_into_wrapper_test()
void lvalue_reference_into_wrapper_test ( )

Definition at line 321 of file MetaUtils_test.cc.

321  {
322 
323  int obj = 1;
324  int & ref = obj;
325  int const& cref = obj;
326  auto refw = std::ref(obj);
327  auto crefw = std::cref(obj);
328 
329  decltype(auto) ref_obj = util::lvalue_reference_into_wrapper(obj );
330  decltype(auto) ref_ref = util::lvalue_reference_into_wrapper(ref );
331  decltype(auto) ref_cref = util::lvalue_reference_into_wrapper(cref );
332  decltype(auto) ref_refw = util::lvalue_reference_into_wrapper(refw );
333  decltype(auto) ref_crefw = util::lvalue_reference_into_wrapper(crefw);
334 
335  // since we have already verified the correctness of
336  // util::lvalue_reference_into_wrapper_t<>, we just check for consistency:
337  static_assert(std::is_same_v<decltype(ref_obj ), util::lvalue_reference_into_wrapper_t<int& >>);
338  static_assert(std::is_same_v<decltype(ref_ref ), util::lvalue_reference_into_wrapper_t<decltype(ref )>>);
339  static_assert(std::is_same_v<decltype(ref_cref ), util::lvalue_reference_into_wrapper_t<decltype(cref )>>);
340  static_assert(std::is_same_v<decltype(ref_refw ), util::lvalue_reference_into_wrapper_t<decltype(refw )>>);
341  static_assert(std::is_same_v<decltype(ref_crefw), util::lvalue_reference_into_wrapper_t<decltype(crefw)>>);
342 
343  BOOST_TEST(util::referenced_address(ref_obj ) == util::referenced_address(obj));
344  BOOST_TEST(util::referenced_address(ref_ref ) == util::referenced_address(obj));
345  BOOST_TEST(util::referenced_address(ref_cref ) == util::referenced_address(obj));
346  BOOST_TEST(util::referenced_address(ref_refw ) == util::referenced_address(obj));
347  BOOST_TEST(util::referenced_address(ref_crefw) == util::referenced_address(obj));
348 
349 } // lvalue_reference_into_wrapper_test()
Namespace for general, non-LArSoft-specific utilities.
STL namespace.
auto lvalue_reference_into_wrapper(T &&obj)
Converts a l-value reference object into a std::reference_wrapper.
Definition: MetaUtils.h:660
auto referenced_address(Ref &&ref)
Returns the address of the referenced object.
Definition: MetaUtils.h:1013
typename lvalue_reference_into_wrapper_type< T >::type lvalue_reference_into_wrapper_t
The type T stripped of all known reference types.
Definition: MetaUtils.h:645
void referenced_address_test ( )

Definition at line 279 of file MetaUtils_test.cc.

279  {
280 
281  int v;
282  int& ref = v;
283  int const& cref = v;
284  auto refw = std::ref(v);
285  auto crefw = std::cref(v);
286 
287  BOOST_TEST(util::referenced_address(ref ) == std::addressof(v));
288  BOOST_TEST(util::referenced_address(cref ) == std::addressof(v));
289  BOOST_TEST(util::referenced_address(refw ) == std::addressof(v));
290  BOOST_TEST(util::referenced_address(crefw) == std::addressof(v));
291 
292 } // referenced_address_test()
auto referenced_address(Ref &&ref)
Returns the address of the referenced object.
Definition: MetaUtils.h:1013
void referenced_addresser_documentation_test ( )

Definition at line 296 of file MetaUtils_test.cc.

296  {
297 
298  /*
299  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
300  * std::vector<int> data(4U, 0);
301  * std::vector<int const*> dataPtr;
302  * std::transform(data.cbegin(), data.cend(), std::back_inserter(dataPtr),
303  * util::reference_addresser());
304  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
305  */
306 
307  std::vector<int> data(4U, 0);
308  std::vector<int const*> dataPtr;
309  std::transform(data.cbegin(), data.cend(), std::back_inserter(dataPtr),
311 
312  // test
313  for (auto&& [ data, dataPtr ]: util::zip(data, dataPtr)) {
314  BOOST_TEST(dataPtr == &data);
315  } // for
316 
317 } // referenced_addresser_documentation_testreferenced_addresser_documentation_test()
Functor applying the proper referenced_address() function.
Definition: MetaUtils.h:609
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
Definition: zip.h:295