Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Namespace pollution in C++

Name: Anonymous 2009-05-25 6:26

I'm working on a C++ project (needs to be fast, sorry,) and I don't want the headers to pollute the namespace with using directives. However, return types like boost::shared_ptr< std::list<File> > tempt me to do so, just so I can shorten my lines. I thought of putting the using directives within my namespace, but that still includes those names when others include my namespace. Maybe that isn't so bad, but I'd much prefer if my namespace only exported names belonging specifically to my namespace, and not those names used internally.

Name: Anonymous 2009-05-25 6:30

>>1
typedef faggot, and use C instead of C++.

Name: Anonymous 2009-05-25 9:03

struct functor_following_boost_guidelines_oh_god_please_kill_me
{
    typedef boost::shared_ptr< std::list<File> > result_type;
    typedef const char* argument_type;
    result_type operator()(argument_type path)
    {
        using std::list;
        result_type list_of_files_duh(new list<File>);
        /* [do retarded stuff] */
        return list_of_files_duh;
    }
};

Name: Anonymous 2009-05-25 9:10

functor_following_boost_guidelines_oh_god_please_kill_me::result_type
convenience_wrapper_for_functor_following_boost_guidelines_oh_god_please_kill_me(functor_following_boost_guidelines_oh_god_please_kill_me::argument_type path)
{
    return functor_following_boost_guidelines_oh_god_please_kill_me()(path);
}

Don't blame me. This is how modern C++ is written. Just look at the libstdc++ headers.
It gets better when you use templates and state. Wanna see?

Name: Anonymous 2009-05-25 9:15

>>4
Wanna see?
Dear god no

Name: Anonymous 2009-05-25 9:28

>>5
Dear god no
Okee-dokee. Don't say I didn't warn you thou.
#ifndef COMPOSE_H
#define COMPOSE_H

#include <functional>

template<class FO, class FI1, class FI2>
struct comp2_fun_t
:    std::binary_function<typename FI1::argument_type,
                         typename FI2::argument_type,
                         typename FO::result_type>
{
    FO f;
    FI1 g;
    FI2 h;

    typedef typename FI1::argument_type first_argument_type;
    typedef typename FI2::argument_type second_argument_type;
    typedef typename FO::result_type result_type;

    comp2_fun_t(const FO& _f, const FI1& _g, const FI2& _h)
    : f(_f), g(_g), h(_h)
    {
    }

    result_type operator()(const first_argument_type& x,
                           const second_argument_type& y)
    {
        return f(g(x), h(y));
    }
};

template<class FO, class FI1, class FI2>
comp2_fun_t<FO, FI1, FI2>
comp2_fun(const FO& _f, const FI1& _g, const FI2& _h)
{
    return comp2_fun_t<FO, FI1, FI2>(_f, _g, _h);
}

#endif//COMPOSE_H

You can go bonkers if you actually write this kind of code.
I will kill you and fuck the body.

Name: Anonymous 2009-05-25 11:05

>>1
typedef boost::shared_ptr< std::list<File> > shared_list_ptr;

Name: Anonymous 2009-05-25 16:00

>>7
I believe you meant to say SharedListPtr, dear sir.

Name: Anonymous 2009-05-25 16:12

>>8
sharedListPtr

Name: Anonymous 2009-05-25 16:23

>>9
Or, in good old C style: pshrdlst

Name: Anonymous 2009-05-25 16:31

>>10
shls*

Name: Anonymous 2009-05-25 16:47

>>10
Or, in good old Java style: AListOfSharedPointersUsingTheBoostLibraryAndSTL

Name: Anonymous 2009-05-25 17:03

>>12
Or, in good old PHP style: shared_listPtr

Name: Anonymous 2009-05-25 17:11

>>13
I think you mean: sharedList_ptr

Name: Anonymous 2009-05-25 18:15

>>13-14
Both are correct because PHP entirely lacks standards.

Name: Anonymous 2009-05-25 20:18

>>14
shared_listPtr looks much better.

Name: Anonymous 2009-05-25 22:07

>>16
I prefer the more sussmanic ``shared_lisp_ttr''.

Don't change these.
Name: Email:
Entire Thread Thread List