Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-07-31 02:19:16

0001 /*----------------------------------------------------------------------
0002 
0003 Test program for edm::vector_transform class.
0004 
0005  ----------------------------------------------------------------------*/
0006 
0007 #include <cassert>
0008 #include <iostream>
0009 #include <string>
0010 #include <boost/algorithm/string.hpp>
0011 #include <catch.hpp>
0012 
0013 #include "FWCore/Utilities/interface/transform.h"
0014 
0015 namespace {
0016   std::string byvalue_toupper(std::string const& value) { return boost::to_upper_copy(value); }
0017 
0018   const std::string byconstvalue_toupper(std::string const& value) { return boost::to_upper_copy(value); }
0019 
0020   std::string& byref_toupper(std::string const& value) { return *new std::string(boost::to_upper_copy(value)); }
0021 
0022   std::string& byconstref_toupper(std::string const& value) { return *new std::string(boost::to_upper_copy(value)); }
0023 }  // namespace
0024 
0025 TEST_CASE("edm::vector_transform", "[transform]") {
0026   const std::vector<std::string> input{"Hello", "World"};
0027   const std::vector<std::string> upper{"HELLO", "WORLD"};
0028   const std::vector<std::string::size_type> size{5, 5};
0029 
0030   auto test_lambda = edm::vector_transform(input, [](std::string const& value) { return value.size(); });
0031   REQUIRE(size == test_lambda);
0032 
0033   REQUIRE(upper == edm::vector_transform(input, byvalue_toupper));
0034   REQUIRE(upper == edm::vector_transform(input, byconstvalue_toupper));
0035   REQUIRE(upper == edm::vector_transform(input, byref_toupper));
0036   REQUIRE(upper == edm::vector_transform(input, byconstref_toupper));
0037 }