Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!lightspeed.eweka.nl!lightspeed.eweka.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:: [': 0.04; 'c++,': 0.07; 'pointers': 0.09; 'python': 0.11; 'c++.': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'objects.': 0.16; 'subject:type': 0.16; 'subject:which': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'version.': 0.19; 'subject:] ': 0.20; 'example': 0.22; 'header:User-Agent:1': 0.23; 'subject:like': 0.24; 'compare': 0.26; 'nearly': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'thus': 0.29; 'code': 0.31; 'piece': 0.31; 'but': 0.35; 'really': 0.36; 'c++': 0.36; 'subject:data': 0.36; 'doing': 0.36; 'similar': 0.36; 'so,': 0.37; 'implement': 0.38; 'message-id:@gmail.com': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'life,': 0.60; 'real': 0.63; 'more': 0.64; 'charset:windows-1252': 0.65; 'bottom': 0.67; 'realized': 0.68 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Sun, 01 Feb 2015 18:02:19 -0700 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: [OT] fortran lib which provide python like data type References: <4822a519-5814-433b-88ad-9bea8a2f83e3@googlegroups.com> <3c31aec4-0c0a-4eb9-aff4-e7b7aa76da21@googlegroups.com> <3d3ef587-a62d-4024-964c-0ac8be023ca3@googlegroups.com> <0b8db0f6-75c5-4a8f-a9a5-51fa936b306e@googlegroups.com> <87zj8zf8bv.fsf@elektro.pacujo.net> <871tma406m.fsf@jester.gateway.sonic.net> <8761bmf4gn.fsf@elektro.pacujo.net> <87oapde98u.fsf@elektro.pacujo.net> In-Reply-To: <87oapde98u.fsf@elektro.pacujo.net> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1422838947 news.xs4all.nl 2900 [2001:888:2000:d::a6]:45258 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3978 X-Received-Body-CRC: 1590491652 Xref: csiph.com comp.lang.python:85036 On 02/01/2015 12:12 PM, Marko Rauhamaa wrote: > So please implement this small piece of Python code in C++ so we can > compare the idioms: So I though I might just for kicks code up a C++ version. In doing so, I realized that idomatically, this particular example would not really use callbacks in real life, but rather stream objects. Would look nearly the same but be more idiomatic C++. However, C++ function pointers are actually pretty slick in C++11. See the example near the bottom of the page: http://en.cppreference.com/w/cpp/utility/functional/function Thus if we were to shoehorn your example into C++, the result would be idiomatically very similar to what you have in your Python code.