lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] static_assert and :argdo [Was: Replacing boost with std C++11]


From: Vadim Zeitlin
Subject: Re: [lmi] static_assert and :argdo [Was: Replacing boost with std C++11]
Date: Tue, 10 Jan 2017 23:13:06 +0100

On Tue, 10 Jan 2017 21:50:28 +0000 Greg Chicares <address@hidden> wrote:

GC> On 2017-01-09 16:49, Vadim Zeitlin wrote:
GC> > On Mon, 9 Jan 2017 16:18:18 +0000 Greg Chicares <address@hidden> wrote:
GC> [...]
GC> > GC> I took a look at other lmi uses of boost, to see whether there's 
anything
GC> > GC> else that's simple and mechanical. The first thing that occurred to 
me was
GC> > GC> enable_if...
GC> > 
GC> >  FWIW the first thing that occurred to me was static_assert(), which has
GC> > special compiler support and is just less ugly than BOOST_STATIC_ASSERT.
GC> 
GC> At the moment I want to ask only about editing. Consider:
GC> 
GC> vim --cmd "args *.?pp | argdo g/boost\/static_assert.hpp/d | 
%s/BOOST_STATIC_ASSERT/static_assert/g | update"
GC> 
GC> for z in *.?pp; do grep -q static_assert $z && sed -i $z 
-e'/boost\static_assert.hpp/d' -e's/BOOST_STATIC_ASSERT/static_assert/g'; done
GC> 
GC> I think I prefer the latter,

 Me too. I've never used Vim from command line and while I might be missing
something, but so far sed, awk or perl -0777 for multiline replacements
were always enough.
 
GC> with small tools in a pipeline: it can hardly
GC> be plainer, and if I make a mistake, it's easier to figure out. OTOH, with
GC> the vim command, I was kind of surprised that '|' worked the way I wanted, 
i.e.
GC>   args *.?pp | argdo { g/boost\/static_assert.hpp/d | 
%s/BOOST_STATIC_ASSERT/static_assert/g | update }
GC> using '{}' to show the hypothetical grouping.
GC> 
GC> Am I missing some hidden glory of vim that somehow makes this easier?

 ":help :argdo" says

                        {cmd} can contain '|' to concatenate several commands.

so apparently this works the way it's supposed to...

GC> Of course I'll want to do
GC>   vim --cmd "vim static_assert *.?pp"
GC> next, to make context-dependent changes like this:
GC> 
GC> -    // Assert that the static_cast doesn't engender undefined behavior.
GC> -    // Double parentheses: don't parse comma as a macro parameter 
separator.
GC>      static_assert
GC> -        ((
GC> +        (
GC>          std::is_base_of
GC>              <MemberSymbolTable<ClassType>
GC>              ,ClassType
GC>              >::value
GC> -        ));
GC> +        );

 FWIW I'd use

        perl -0777 -i'' -pe 
's/BOOST_STATIC_ASSERT(\s*)\(\(([^;]+)\)\);/static_assert\1(\2);/' *.?pp

for this. This even seems to work correctly. And I only had to do "git
reset --hard HEAD" once while testing it.

 Regards,
VZ


reply via email to

[Prev in Thread] Current Thread [Next in Thread]