SlideShare una empresa de Scribd logo
1 de 20
Descargar para leer sin conexión
Replace OutputIterator and Extended Range



                                     Akira Takahashi (Japan)
                                          LongGate CO.,LTD.
Site: https://sites.google.com/site/faithandbrave/about/en
                                         Twitter: @cpp_akira
                                  C++Now! 2012 Library in a Week
Akira Takahashi profile
• C++ Standard Committee, Japan Expert Member
• P-Stade C++ Libraries committer
• Japanese C++ Community Manager
   – boostjp : Boost Japanese Information Site
      https://sites.google.com/site/boostjp/
   – cpprefjp: C++11 Library Reference Site
      https://sites.google.com/site/cpprefjp/
   – Blog : Japanese C++ Programmers Activity
      http://cppjp.blogspot.com/
   – Boost.StudyMeeting (so to say, Japanese BoostCon/C++Now!)
       • participation person is 100+
• My Book : C++ Template Techniques
  http://www.amazon.co.jp/dp/4797354534/
• My Magazine: Programmers' Grimoire
  http://longgate.co.jp/products.html
note:
        I can speak very little English!
I may not answer your question immediately…
1st

OutputIterators Must Go
This Idea Overview
• Output Iterators are now unnecessary
  because C++11 is there.
• Some STL algorithm can replace
  from Output Iterator to UnaryFunction.
Basic Example: std::copy
std::copy can replace std::for_each with lambda.
 Before:
 std::vector<int> v = {1, 2, 3};
 std::vector<int> result;

 std::copy(v.begin(), v.end(), std::back_inserter(result));
 After:
 std::vector<int> v = {1, 2, 3};
 std::vector<int> result;

 std::for_each(v.begin(), v.end(),
                   [&](int x) { result.push_back(x); });

            This replacement is failry useful.
More Useful Example:
   set_union, set_intersection, set_difference
STL set algorithms using Output Iterator aren't useful.

 Now STL Algorithm
 std::set<int> a = {1, 2, 3};
 std::set<int> b = {4, 5, 6};
 std::set<int> result;

 std::set_union(a.begin(), a.end(),
                 b.begin(), b.end(),
                 std::inserter(result, result.end()));


               Insert Iterator Adaptor is not useful!
                  Custom operation is not easy.
More Useful Example:
   set_union, set_intersection, set_difference
STL set algorithm using Output Iterator. Not useful.

 New STL Algorithm
 std::set<int> a = {1, 2, 3};
 std::set<int> b = {4, 5, 6};
 std::set<int> result;

 make_union(a.begin(), a.end(),
             b.begin(), b.end(),
             [](int x) { result.insert(x); });

       Output Iterator canreplace to UnaryFunction.
   It's accutually useful, easily to customize operation.
                This implementation is here:
     https://github.com/faithandbrave/Set-Algorithm
2nd

 OvenToBoost project
OvenToBoost project overview
• Oven is Range Library in P-Stade C++ Libraries
• Oven is more useful than Boost.Range
• OvenToBoost project is porting from Oven To Boost
  as extended Boost.Range
• https://github.com/faithandbrave/OvenToBoost
Boost.Range issues
• There are not many Range adaptors.
  – nothing "taken"
  – nothing "dropped"
  – nothing Infinite Range
  – etc…
• Boost.Range's Range adaptors can't use
  lambda
• Oven has solution for these issues
taken Range Adaptor

const std::vector<int> v = {3, 1, 4, 2, 5};

boost::for_each(v | taken(2), print);

3
1
dropped Range Adaptor

const std::vector<int> v = {3, 1, 4, 2, 5};

boost::for_each(v | dropped(2), print);

4
2
5
elements Range Adaptor
struct Person {
  int id;
  std::string name;
  …
};
BOOST_FUSION_ADAPT_STRUCT(…)

const std::vector<Person> v = {
    {1, "Alice"}
    {2, "Carol"}
    {3, "Bob"}
 };

boost::for_each(v | elements<1>(), print);

Alice,Carol,Bob
elements_key Range Adaptor
struct id_tag {}; struct name_tag {};

struct Person {
  int id;
  std::string name;
  …
};
BOOST_FUSION_ADAPT_ASSOC_STRUCT(…)

const std::vector<Person> v = {
    {1, "Alice"}
    {2, "Carol"}
    {3, "Bob"}
 };

boost::for_each(v | elements_key<name_tag>(), print);

Alice,Carol,Bob
iteration function

int next(int x) { return x * 2; }

boost::for_each(iteration(1, next) | taken(5), print);

1
2
4
8
16
regular function
template <class InputIterator, class F>
F for_each_(InputIterator first, InputIterator last, F f) {
  InputIterator it; // default construct
  it = first; // copy assign

    while (it != last) { f(*it); ++i; }
    return f;
}

template <class Range, class F>
F for_each_(const Range& r, F f)
{ return for_each(boost::begin(r), boost::end(r), f); }

using boost::lambda::_1;
for_each_(r | filtered(_1 % 2 == 0), f);          // Error!
for_each_(r | filtered(regular(_1 % 2 == 0)), f); // OK
regular operator|+()
template <class InputIterator, class F>
F for_each_(InputIterator first, InputIterator last, F f) {
  InputIterator it; // default construct
  it = first; // copy assign

    while (it != last) { f(*it); ++i; }
    return f;
}

template <class Range, class F>
F for_each_(const Range& r, F f)
{ return for_each(boost::begin(r), boost::end(r), f); }

using boost::lambda::_1;
for_each_(r | filtered(_1 % 2 == 0), f); // Error!
for_each_(r |+ filtered(_1 % 2 == 0), f); // OK
Combination Example: Prime list
range sieve(range r)
{
  return r | dropped(1) |+ filtered(_1 % value_front(r) != 0);
}

range primes =
    iteration(range(
      iteration(2, regular(_1 + 1))), sieve) | transformed(value_front);


for_each(primes, print);


2 3 5 7 11 …
OvenToBoost now status
•   Primary implementation has been complete.
•   Test has been complete.
•   But documentation is late…
•   I would like to submit a review request to Boost.

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

[C++ korea] effective modern c++ study item 3 understand decltype +이동우
[C++ korea] effective modern c++ study   item 3 understand decltype +이동우[C++ korea] effective modern c++ study   item 3 understand decltype +이동우
[C++ korea] effective modern c++ study item 3 understand decltype +이동우
 
2 + 2 = 5: Monkey-patching CPython with ctypes to conform to Party doctrine
2 + 2 = 5: Monkey-patching CPython with ctypes to conform to Party doctrine2 + 2 = 5: Monkey-patching CPython with ctypes to conform to Party doctrine
2 + 2 = 5: Monkey-patching CPython with ctypes to conform to Party doctrine
 
Virtual Functions
Virtual FunctionsVirtual Functions
Virtual Functions
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
Pointers+(2)
Pointers+(2)Pointers+(2)
Pointers+(2)
 
Pointers
PointersPointers
Pointers
 
Java Script Workshop
Java Script WorkshopJava Script Workshop
Java Script Workshop
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)
 
Functions (Computer programming and utilization)
Functions (Computer programming and utilization)Functions (Computer programming and utilization)
Functions (Computer programming and utilization)
 
C++ Presentation
C++ PresentationC++ Presentation
C++ Presentation
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ Programming
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
 
03 function overloading
03 function overloading03 function overloading
03 function overloading
 
C tutorial
C tutorialC tutorial
C tutorial
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by Example
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
The Style of C++ 11
The Style of C++ 11The Style of C++ 11
The Style of C++ 11
 
C
CC
C
 
Function C++
Function C++ Function C++
Function C++
 

Similar a Replace OutputIterator and Extend Range

C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11Jadavsejal
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupSyedHaroonShah4
 
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)Brendan Eich
 
Writing DSL with Applicative Functors
Writing DSL with Applicative FunctorsWriting DSL with Applicative Functors
Writing DSL with Applicative FunctorsDavid Galichet
 
Memory Management with Java and C++
Memory Management with Java and C++Memory Management with Java and C++
Memory Management with Java and C++Mohammad Shaker
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoMatt Stine
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionPaulo Morgado
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorJussi Pohjolainen
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ AdvancedVivek Das
 
Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationGlobalLogic Ukraine
 

Similar a Replace OutputIterator and Extend Range (20)

10.ppt
10.ppt10.ppt
10.ppt
 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11
 
Functions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrupFunctions And Header Files In C++ | Bjarne stroustrup
Functions And Header Files In C++ | Bjarne stroustrup
 
What's New in C++ 11?
What's New in C++ 11?What's New in C++ 11?
What's New in C++ 11?
 
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
 
C
CC
C
 
Return of c++
Return of c++Return of c++
Return of c++
 
Writing DSL with Applicative Functors
Writing DSL with Applicative FunctorsWriting DSL with Applicative Functors
Writing DSL with Applicative Functors
 
Memory Management with Java and C++
Memory Management with Java and C++Memory Management with Java and C++
Memory Management with Java and C++
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
 
C Programming Homework Help
C Programming Homework HelpC Programming Homework Help
C Programming Homework Help
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
C to perl binding
C to perl bindingC to perl binding
C to perl binding
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
C++
C++C++
C++
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
 
02basics
02basics02basics
02basics
 
Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python Integration
 

Más de Akira Takahashi (20)

Cpp20 overview language features
Cpp20 overview language featuresCpp20 overview language features
Cpp20 overview language features
 
Cppmix 02
Cppmix 02Cppmix 02
Cppmix 02
 
Cppmix 01
Cppmix 01Cppmix 01
Cppmix 01
 
Modern C++ Learning
Modern C++ LearningModern C++ Learning
Modern C++ Learning
 
cpprefjp documentation
cpprefjp documentationcpprefjp documentation
cpprefjp documentation
 
C++1z draft
C++1z draftC++1z draft
C++1z draft
 
Boost tour 1_61_0 merge
Boost tour 1_61_0 mergeBoost tour 1_61_0 merge
Boost tour 1_61_0 merge
 
Boost tour 1_61_0
Boost tour 1_61_0Boost tour 1_61_0
Boost tour 1_61_0
 
error handling using expected
error handling using expectederror handling using expected
error handling using expected
 
Boost tour 1.60.0 merge
Boost tour 1.60.0 mergeBoost tour 1.60.0 merge
Boost tour 1.60.0 merge
 
Boost tour 1.60.0
Boost tour 1.60.0Boost tour 1.60.0
Boost tour 1.60.0
 
Boost container feature
Boost container featureBoost container feature
Boost container feature
 
Boost Tour 1_58_0 merge
Boost Tour 1_58_0 mergeBoost Tour 1_58_0 merge
Boost Tour 1_58_0 merge
 
Boost Tour 1_58_0
Boost Tour 1_58_0Boost Tour 1_58_0
Boost Tour 1_58_0
 
C++14 solve explicit_default_constructor
C++14 solve explicit_default_constructorC++14 solve explicit_default_constructor
C++14 solve explicit_default_constructor
 
C++14 enum hash
C++14 enum hashC++14 enum hash
C++14 enum hash
 
Multi paradigm design
Multi paradigm designMulti paradigm design
Multi paradigm design
 
Start Concurrent
Start ConcurrentStart Concurrent
Start Concurrent
 
Programmer mind
Programmer mindProgrammer mind
Programmer mind
 
Boost.Study 14 Opening
Boost.Study 14 OpeningBoost.Study 14 Opening
Boost.Study 14 Opening
 

Último

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Último (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Replace OutputIterator and Extend Range

  • 1. Replace OutputIterator and Extended Range Akira Takahashi (Japan) LongGate CO.,LTD. Site: https://sites.google.com/site/faithandbrave/about/en Twitter: @cpp_akira C++Now! 2012 Library in a Week
  • 2. Akira Takahashi profile • C++ Standard Committee, Japan Expert Member • P-Stade C++ Libraries committer • Japanese C++ Community Manager – boostjp : Boost Japanese Information Site https://sites.google.com/site/boostjp/ – cpprefjp: C++11 Library Reference Site https://sites.google.com/site/cpprefjp/ – Blog : Japanese C++ Programmers Activity http://cppjp.blogspot.com/ – Boost.StudyMeeting (so to say, Japanese BoostCon/C++Now!) • participation person is 100+ • My Book : C++ Template Techniques http://www.amazon.co.jp/dp/4797354534/ • My Magazine: Programmers' Grimoire http://longgate.co.jp/products.html
  • 3. note: I can speak very little English! I may not answer your question immediately…
  • 5. This Idea Overview • Output Iterators are now unnecessary because C++11 is there. • Some STL algorithm can replace from Output Iterator to UnaryFunction.
  • 6. Basic Example: std::copy std::copy can replace std::for_each with lambda. Before: std::vector<int> v = {1, 2, 3}; std::vector<int> result; std::copy(v.begin(), v.end(), std::back_inserter(result)); After: std::vector<int> v = {1, 2, 3}; std::vector<int> result; std::for_each(v.begin(), v.end(), [&](int x) { result.push_back(x); }); This replacement is failry useful.
  • 7. More Useful Example: set_union, set_intersection, set_difference STL set algorithms using Output Iterator aren't useful. Now STL Algorithm std::set<int> a = {1, 2, 3}; std::set<int> b = {4, 5, 6}; std::set<int> result; std::set_union(a.begin(), a.end(), b.begin(), b.end(), std::inserter(result, result.end())); Insert Iterator Adaptor is not useful! Custom operation is not easy.
  • 8. More Useful Example: set_union, set_intersection, set_difference STL set algorithm using Output Iterator. Not useful. New STL Algorithm std::set<int> a = {1, 2, 3}; std::set<int> b = {4, 5, 6}; std::set<int> result; make_union(a.begin(), a.end(), b.begin(), b.end(), [](int x) { result.insert(x); }); Output Iterator canreplace to UnaryFunction. It's accutually useful, easily to customize operation. This implementation is here: https://github.com/faithandbrave/Set-Algorithm
  • 10. OvenToBoost project overview • Oven is Range Library in P-Stade C++ Libraries • Oven is more useful than Boost.Range • OvenToBoost project is porting from Oven To Boost as extended Boost.Range • https://github.com/faithandbrave/OvenToBoost
  • 11. Boost.Range issues • There are not many Range adaptors. – nothing "taken" – nothing "dropped" – nothing Infinite Range – etc… • Boost.Range's Range adaptors can't use lambda • Oven has solution for these issues
  • 12. taken Range Adaptor const std::vector<int> v = {3, 1, 4, 2, 5}; boost::for_each(v | taken(2), print); 3 1
  • 13. dropped Range Adaptor const std::vector<int> v = {3, 1, 4, 2, 5}; boost::for_each(v | dropped(2), print); 4 2 5
  • 14. elements Range Adaptor struct Person { int id; std::string name; … }; BOOST_FUSION_ADAPT_STRUCT(…) const std::vector<Person> v = { {1, "Alice"} {2, "Carol"} {3, "Bob"} }; boost::for_each(v | elements<1>(), print); Alice,Carol,Bob
  • 15. elements_key Range Adaptor struct id_tag {}; struct name_tag {}; struct Person { int id; std::string name; … }; BOOST_FUSION_ADAPT_ASSOC_STRUCT(…) const std::vector<Person> v = { {1, "Alice"} {2, "Carol"} {3, "Bob"} }; boost::for_each(v | elements_key<name_tag>(), print); Alice,Carol,Bob
  • 16. iteration function int next(int x) { return x * 2; } boost::for_each(iteration(1, next) | taken(5), print); 1 2 4 8 16
  • 17. regular function template <class InputIterator, class F> F for_each_(InputIterator first, InputIterator last, F f) { InputIterator it; // default construct it = first; // copy assign while (it != last) { f(*it); ++i; } return f; } template <class Range, class F> F for_each_(const Range& r, F f) { return for_each(boost::begin(r), boost::end(r), f); } using boost::lambda::_1; for_each_(r | filtered(_1 % 2 == 0), f); // Error! for_each_(r | filtered(regular(_1 % 2 == 0)), f); // OK
  • 18. regular operator|+() template <class InputIterator, class F> F for_each_(InputIterator first, InputIterator last, F f) { InputIterator it; // default construct it = first; // copy assign while (it != last) { f(*it); ++i; } return f; } template <class Range, class F> F for_each_(const Range& r, F f) { return for_each(boost::begin(r), boost::end(r), f); } using boost::lambda::_1; for_each_(r | filtered(_1 % 2 == 0), f); // Error! for_each_(r |+ filtered(_1 % 2 == 0), f); // OK
  • 19. Combination Example: Prime list range sieve(range r) { return r | dropped(1) |+ filtered(_1 % value_front(r) != 0); } range primes = iteration(range( iteration(2, regular(_1 + 1))), sieve) | transformed(value_front); for_each(primes, print); 2 3 5 7 11 …
  • 20. OvenToBoost now status • Primary implementation has been complete. • Test has been complete. • But documentation is late… • I would like to submit a review request to Boost.