[Nfd-dev] C++11 code style

Junxiao Shi shijunxiao at email.arizona.edu
Sun Nov 2 18:29:47 PST 2014


Dear folks

List initialization: I suggest the following rule:

rule x. List initialization should have the following form:

T object { arg1, arg2 };

T { arg1, arg2 };

new T { arg1, arg2 };

return { arg1, arg2 };
function({ arg1, arg2 }, otherArgument);

object[{ arg1, arg2 }];

T({ arg1, arg2 })


class Class
{

private:

  T m_member = { arg1, arg2 };

};

Class::Class()

  : m_member { arg1, arg2 }
{
}

T object = { arg1, arg2 };


Static assertion: I suggest the following rule:

rule x. BOOST_ASSERT and BOOST_ASSERT_MSG are preferred over assert.
BOOST_STATIC_ASSERT and BOOST_STATIC_ASSERT_MSG are preferred over
static_assert.
The reason is that BOOST_* macros are more eye-catching with upper case.

Right angle brackets: std::list<std::list<int>> should be preferred. This
doesn't need a new rule because it's not forbidden by any rule.

Strongly-typed enumerations: Yes we can use them. This doesn't need a new
rule because it's not forbidden by any rule.

STL classes and functions vs Boost classes and functions: This isn't a code
style problem. Generally STL is preferred.

Yours, Junxiao

On Sun, Nov 2, 2014 at 6:29 PM, Davide Pesavento <davide.pesavento at lip6.fr>
wrote:

>
> * Initializer lists and uniform initializations [1]. Where can we use
> them and how? Spaces around braces?
>
> * New function declaration syntax with trailing return type. Can we use it?
> (I'd say yes but only if really necessary)
>
> * Static assertions [2]. Are they preferred to BOOST_STATIC_ASSERT?
>
> * Right angle brackets. `list<list<int> >` or `list<list<int>>`? (the
> latter syntax was not allowed in C++98)
>
> * Strongly-typed (aka scoped) enumerations [3]. Can we use them? Are
> they preferred to old-style enums? `enum struct` or `enum class`?
>
> * Should we prefer new classes and functions of the standard library
> (std::) when they're also available in boost?
>
> [1] http://en.cppreference.com/w/cpp/language/list_initialization
> [2] http://en.cppreference.com/w/cpp/language/static_assert
> [3] http://en.cppreference.com/w/cpp/language/enum
>
> Best,
> Davide
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/nfd-dev/attachments/20141102/2e5f0106/attachment.html>


More information about the Nfd-dev mailing list