Changeset 16 for cppstreams


Ignore:
Timestamp:
Dec 5, 2012, 10:26:54 PM (13 years ago)
Author:
gobi
Message:

fixing spaces, tabs

Location:
cppstreams
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cppstreams/stream.h

    r3 r16  
    33 * All rights reserved. 
    44 * 
    5  * This software was developed by Attila Gobi and Zalan Szugyi.  
     5 * This software was developed by Attila Gobi and Zalan Szugyi. 
    66 * The project was supported by the European Union and co-financed by the 
    77 * European Social Fund (grant agreement no. TAMOP 4.2.1./B-09/1/KMR-2010-0003) 
     
    99 * Redistribution and use in source and binary forms, with or without 
    1010 * modification, are permitted provided that the following conditions are met: 
    11  * 1. Redistributions of source code must retain the above copyright  
     11 * 1. Redistributions of source code must retain the above copyright 
    1212 *    notice, this list of conditions and the following disclaimer. 
    13  * 2. Redistributions in binary form must reproduce the above copyright  
     13 * 2. Redistributions in binary form must reproduce the above copyright 
    1414 *    notice, this list of conditions and the following disclaimer in the 
    1515 *    documentation and/or other materials provided with the distribution. 
     
    6161    stream(const stream<T> &o) 
    6262        : impl_(o.impl_->clone()) 
    63     {  
     63    { 
    6464    } 
    6565 
     
    6969        std::swap(impl_, o.impl_); 
    7070    } 
    71      
     71 
    7272    stream<T> & operator = (stream<T> &&o) 
    7373    { 
    74         if(this != &o) { 
    75                 std::swap(impl_, o.impl_); 
    76                 return *this; 
    77         } 
    78     } 
    79      
     74        if(this != &o) { 
     75            std::swap(impl_, o.impl_); 
     76            return *this; 
     77        } 
     78    } 
     79 
    8080    ~stream() 
    8181    { 
     
    8484 
    8585    struct iterator { 
    86         iterator& operator ++()  
     86        iterator& operator ++() 
    8787        { 
    8888            (*impl_)->next(*this); 
     
    128128    struct addimpl: public impl { 
    129129        addimpl(const T &a, ST &&s) 
    130             : a_(a), s_(std::forward<ST>(s))  
     130            : a_(a), s_(std::forward<ST>(s)) 
    131131        { } 
    132132 
    133         const T &get(const iterator &)  
     133        const T &get(const iterator &) 
    134134        { 
    135135            return a_; 
     
    141141        } 
    142142 
    143         impl *clone()  
     143        impl *clone() 
    144144        { 
    145145            return new addimpl<ST>(a_, std::forward<ST>(s_)); 
     
    160160 
    161161        const T &get(const iterator &it) 
    162         {  
     162        { 
    163163            *(it.impl_)=new addimpl<stream<T>&&>(op_(*it1), stream<T>(this)); 
    164164            ++it1; 
     
    166166        } 
    167167 
    168         void next(iterator &it)  
     168        void next(iterator &it) 
    169169        { 
    170170            *(it.impl_)=new addimpl<stream<T>&&>(op_(*it1), stream<T>(this)); 
     
    173173        } 
    174174 
    175         impl *clone()  
     175        impl *clone() 
    176176        { 
    177177            return new mapimpl2<Op, ST>(op_, std::forward<ST>(s_)); 
     
    181181        iterator it1; 
    182182        Op op_; 
    183         }; 
     183    }; 
    184184 
    185185    template<typename Op, typename ST> 
     
    189189        { } 
    190190 
    191         const T &get(const iterator &it)  
     191        const T &get(const iterator &it) 
    192192        { 
    193193            impl *x = new mapimpl2<Op, ST>(op_, std::forward<ST>(s_)); 
    194194            *(it.impl_) = x; 
    195              
     195 
    196196            delete this; 
    197197            return *it; 
     
    206206        } 
    207207 
    208         impl *clone()  
     208        impl *clone() 
    209209        { 
    210210            return new mapimpl<Op, ST>(op_, std::forward<ST>(s_)); 
     
    213213    private: 
    214214        typename storage_type<ST>::type s_; 
    215                 Op op_; 
     215        Op op_; 
    216216    }; 
    217217 
     
    223223        { } 
    224224 
    225         const T &get(const iterator &it)  
    226         {  
     225        const T &get(const iterator &it) 
     226        { 
    227227            impl *x = new zipimpl2<Op, ST1, ST2>(op_, std::forward<ST1>(s1_), std::forward<ST2>(s2_)); 
    228228            *(it.impl_) = x; 
     
    231231        } 
    232232 
    233         void next(iterator &it)  
     233        void next(iterator &it) 
    234234        { 
    235235            impl *x = new zipimpl2<Op, ST1, ST2>(op_, std::forward<ST1>(s1_), std::forward<ST2>(s2_)); 
     
    239239        } 
    240240 
    241         impl *clone()  
     241        impl *clone() 
    242242        { 
    243243            return new zipimpl<Op, ST1, ST2>(op_, std::forward<ST1>(s1_), std::forward<ST2>(s2_)); 
     
    259259 
    260260        const T &get(const iterator &it) 
    261         {  
     261        { 
    262262            *(it.impl_)=new addimpl<stream<T>&&>(op_(*it1, *it2), stream<T>(this)); 
    263263            ++it1; 
     
    266266        } 
    267267 
    268         void next(iterator &it)  
     268        void next(iterator &it) 
    269269        { 
    270270            *(it.impl_)=new addimpl<stream<T>&&>(op_(*it1, *it2), stream<T>(this)); 
     
    274274        } 
    275275 
    276         impl *clone()  
     276        impl *clone() 
    277277        { 
    278278            return new zipimpl2<Op, ST1, ST2>(op_, std::forward<ST1>(s1_), std::forward<ST2>(s2_)); 
     
    286286 
    287287public: 
    288         template <typename S, typename U> 
    289         friend stream<U> operator <<= (const U& a, S && s); 
    290      
     288    template <typename S, typename U> 
     289    friend stream<U> operator <<= (const U& a, S && s); 
     290 
    291291    template <typename Op, typename ST1, typename ST2> 
    292292    static stream<T> zipwith(Op op, ST1 &&s1, ST2 &&s2) 
     
    294294        return stream(new zipimpl<Op, decltype(s1), decltype(s2)>(op, std::forward<ST1>(s1), std::forward<ST2>(s2))); 
    295295    } 
    296      
    297         template <typename ST1, typename Op> 
     296 
     297    template <typename ST1, typename Op> 
    298298    static stream<T> map(Op op, ST1 &&s1) 
    299299    { 
     
    301301    } 
    302302 
    303         static stream<T> pure(const T& v) 
    304         { 
    305                 stream<T> s = v<<=s; 
    306                 return s; 
    307         } 
     303    static stream<T> pure(const T& v) 
     304    { 
     305        stream<T> s = v<<=s; 
     306        return s; 
     307    } 
    308308}; 
    309309 
     
    311311struct stream_value_type 
    312312{ 
    313         typedef typename std::remove_reference<ST>::type::value_type type; 
     313    typedef typename std::remove_reference<ST>::type::value_type type; 
    314314}; 
    315315 
     
    317317stream<U> operator <<= (const U& a, S && s) 
    318318{ 
    319         return stream<U>(new typename stream<U>::template addimpl<decltype(s)>(a, std::forward<S>(s))); 
    320 } 
    321      
     319    return stream<U>(new typename stream<U>::template addimpl<decltype(s)>(a, std::forward<S>(s))); 
     320} 
     321 
    322322template<typename ST1, typename ST2, typename T=typename stream_value_type<ST1>::type> 
    323323stream<T> operator +(ST1 &&s1, ST2 &&s2) 
    324324{ 
    325         return stream<T>::zipwith(std::plus<T>(), std::forward<ST1>(s1), std::forward<ST2>(s2)); 
     325    return stream<T>::zipwith(std::plus<T>(), std::forward<ST1>(s1), std::forward<ST2>(s2)); 
    326326} 
    327327 
     
    329329stream<T> operator -(ST1 &&s1, ST2 &&s2) 
    330330{ 
    331         return stream<T>::zipwith(std::minus<T>(), std::forward<ST1>(s1), std::forward<ST2>(s2)); 
     331    return stream<T>::zipwith(std::minus<T>(), std::forward<ST1>(s1), std::forward<ST2>(s2)); 
    332332} 
    333333 
     
    335335stream<T> operator *(ST1 &&s1, ST2 &&s2) 
    336336{ 
    337         return stream<T>::zipwith(std::multiplies<T>(), std::forward<ST1>(s1), std::forward<ST2>(s2)); 
     337    return stream<T>::zipwith(std::multiplies<T>(), std::forward<ST1>(s1), std::forward<ST2>(s2)); 
    338338} 
    339339 
     
    341341stream<T> operator /(ST1 &&s1, ST2 &&s2) 
    342342{ 
    343         return stream<T>::zipwith(std::divides<T>(), std::forward<ST1>(s1), std::forward<ST2>(s2)); 
     343    return stream<T>::zipwith(std::divides<T>(), std::forward<ST1>(s1), std::forward<ST2>(s2)); 
    344344} 
    345345 
     
    347347stream<T> operator %(ST1 &&s1, ST2 &&s2) 
    348348{ 
    349         return stream<T>::zipwith(std::modulus<T>(), std::forward<ST1>(s1), std::forward<ST2>(s2)); 
     349    return stream<T>::zipwith(std::modulus<T>(), std::forward<ST1>(s1), std::forward<ST2>(s2)); 
    350350} 
    351351 
     
    353353stream<T> operator -(ST &&s) 
    354354{ 
    355         return stream<T>::map(std::negate<T>(), std::forward<ST>(s)); 
     355    return stream<T>::map(std::negate<T>(), std::forward<ST>(s)); 
    356356} 
    357357 
     
    360360struct stream_proxy 
    361361{ 
    362         stream_proxy(unsigned long long i): x(i) {} 
    363         template <typename T> 
    364         operator stream<T> () { 
    365                 stream<T> a = static_cast<T>(x)<<=a; 
    366                 return a; 
    367         } 
    368         unsigned long long x; 
     362    stream_proxy(unsigned long long i): x(i) {} 
     363    template <typename T> 
     364    operator stream<T> () { 
     365        stream<T> a = static_cast<T>(x)<<=a; 
     366        return a; 
     367    } 
     368    unsigned long long x; 
    369369}; 
    370370 
    371371stream_proxy operator "" _s (unsigned long long i) 
    372372{ 
    373         return stream_proxy(i); 
     373    return stream_proxy(i); 
    374374} 
    375375 
  • cppstreams/test_fibonacci.cc

    r3 r16  
    99 * Redistribution and use in source and binary forms, with or without 
    1010 * modification, are permitted provided that the following conditions are met: 
    11  * 1. Redistributions of source code must retain the above copyright  
     11 * 1. Redistributions of source code must retain the above copyright 
    1212 *    notice, this list of conditions and the following disclaimer. 
    13  * 2. Redistributions in binary form must reproduce the above copyright  
     13 * 2. Redistributions in binary form must reproduce the above copyright 
    1414 *    notice, this list of conditions and the following disclaimer in the 
    1515 *    documentation and/or other materials provided with the distribution. 
     
    5252int main() 
    5353{ 
    54         stream<long> s = 0l<<=s+(1l<<=s); 
    55     compare(s,  {0l,1l,1l,2l,3l,5l,8l,13l,21l,34l}, 1); 
     54  stream<long> s = 0l<<=s+(1l<<=s); 
    5655 
    57     const int n = 200000; 
    58     struct timeval tv1, tv2; 
    59     struct timezone tz; 
     56  compare(s,  {0l,1l,1l,2l,3l,5l,8l,13l,21l,34l}, 1); 
    6057 
    61     gettimeofday(&tv1, &tz); 
    62     stream<long>::iterator it = s.begin(); 
    63     for(int i=0; i<n; ++i) ++it; 
    64     *it;  
    65     gettimeofday(&tv2, &tz); 
    66     std::cout<<timeval_diff(tv2, tv1)<<std::endl; 
     58  const int n = 200000; 
     59  struct timeval tv1, tv2; 
     60  struct timezone tz; 
    6761 
    68     gettimeofday(&tv1, &tz); 
    69     fib(n); 
    70     gettimeofday(&tv2, &tz); 
    71     std::cout<<timeval_diff(tv2, tv1)<<std::endl; 
     62  gettimeofday(&tv1, &tz); 
     63  stream<long>::iterator it = s.begin(); 
     64  for(int i=0; i<n; ++i) ++it; 
     65  *it; 
     66  gettimeofday(&tv2, &tz); 
     67  std::cout<<timeval_diff(tv2, tv1)<<std::endl; 
    7268 
    73         return 0; 
     69  gettimeofday(&tv1, &tz); 
     70  fib(n); 
     71  gettimeofday(&tv2, &tz); 
     72  std::cout<<timeval_diff(tv2, tv1)<<std::endl; 
     73 
     74  return 0; 
    7475} 
Note: See TracChangeset for help on using the changeset viewer.