Skip to content

Commit a0b95e7

Browse files
committed
Refactor to trailing return types
- Trailing return types everywhere - Optionally, return type deduction where sensible (simple and short functions) This is related to introduction of common .clang-format, see boostorg#596 (comment)
1 parent bbdce36 commit a0b95e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+655
-522
lines changed

include/boost/gil/algorithm.hpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,38 +83,38 @@ struct binary_operation_obj
8383
using result_type = Result;
8484

8585
template <typename V1, typename V2> BOOST_FORCEINLINE
86-
result_type operator()(const std::pair<const V1*,const V2*>& p) const {
86+
auto operator()(const std::pair<const V1*,const V2*>& p) const -> result_type {
8787
return apply(*p.first, *p.second, typename views_are_compatible<V1,V2>::type());
8888
}
8989

9090
template <typename V1, typename V2> BOOST_FORCEINLINE
91-
result_type operator()(const V1& v1, const V2& v2) const {
91+
auto operator()(const V1& v1, const V2& v2) const -> result_type {
9292
return apply(v1, v2, typename views_are_compatible<V1,V2>::type());
9393
}
9494

95-
result_type operator()(const error_t&) const { throw std::bad_cast(); }
95+
auto operator()(const error_t&) const -> result_type { throw std::bad_cast(); }
9696
private:
9797

9898
// dispatch from apply overload to a function with distinct name
9999
template <typename V1, typename V2>
100100
BOOST_FORCEINLINE
101-
result_type apply(V1 const& v1, V2 const& v2, std::false_type) const
101+
auto apply(V1 const& v1, V2 const& v2, std::false_type) const -> result_type
102102
{
103103
return ((const Derived*)this)->apply_incompatible(v1, v2);
104104
}
105105

106106
// dispatch from apply overload to a function with distinct name
107107
template <typename V1, typename V2>
108108
BOOST_FORCEINLINE
109-
result_type apply(V1 const& v1, V2 const& v2, std::true_type) const
109+
auto apply(V1 const& v1, V2 const& v2, std::true_type) const -> result_type
110110
{
111111
return ((const Derived*)this)->apply_compatible(v1, v2);
112112
}
113113

114114
// function with distinct name - it can be overloaded by subclasses
115115
template <typename V1, typename V2>
116116
BOOST_FORCEINLINE
117-
result_type apply_incompatible(V1 const& /*v1*/, V2 const& /*v2*/) const
117+
auto apply_incompatible(V1 const& /*v1*/, V2 const& /*v2*/) const -> result_type
118118
{
119119
throw std::bad_cast();
120120
}
@@ -149,9 +149,10 @@ auto copy(
149149
/// \ingroup STLOptimizations
150150
/// \brief Copy when both src and dst are interleaved and of the same type can be just memmove
151151
template<typename T, typename CS>
152-
BOOST_FORCEINLINE boost::gil::pixel<T,CS>*
153-
copy(const boost::gil::pixel<T,CS>* first, const boost::gil::pixel<T,CS>* last,
154-
boost::gil::pixel<T,CS>* dst) {
152+
BOOST_FORCEINLINE
153+
auto copy(const boost::gil::pixel<T,CS>* first, const boost::gil::pixel<T,CS>* last,
154+
boost::gil::pixel<T,CS>* dst) -> boost::gil::pixel<T,CS>*
155+
{
155156
return (boost::gil::pixel<T,CS>*)std::copy((unsigned char*)first,(unsigned char*)last, (unsigned char*)dst);
156157
}
157158
} // namespace std
@@ -168,7 +169,8 @@ namespace std {
168169
/// \ingroup STLOptimizations
169170
/// \brief Copy when both src and dst are planar pointers is copy for each channel
170171
template<typename CS, typename IC1, typename IC2> BOOST_FORCEINLINE
171-
boost::gil::planar_pixel_iterator<IC2,CS> copy(boost::gil::planar_pixel_iterator<IC1,CS> first, boost::gil::planar_pixel_iterator<IC1,CS> last, boost::gil::planar_pixel_iterator<IC2,CS> dst) {
172+
auto copy(boost::gil::planar_pixel_iterator<IC1,CS> first, boost::gil::planar_pixel_iterator<IC1,CS> last, boost::gil::planar_pixel_iterator<IC2,CS> dst) -> boost::gil::planar_pixel_iterator<IC2,CS>
173+
{
172174
boost::gil::gil_function_requires<boost::gil::ChannelsCompatibleConcept<typename std::iterator_traits<IC1>::value_type,typename std::iterator_traits<IC2>::value_type>>();
173175
static_for_each(first,last,dst,boost::gil::detail::copy_fn<IC1,IC2>());
174176
return dst+(last-first);
@@ -244,7 +246,7 @@ struct copier_n<iterator_from_2d<IL>,iterator_from_2d<OL>> {
244246
};
245247

246248
template <typename SrcIterator, typename DstIterator>
247-
BOOST_FORCEINLINE DstIterator copy_with_2d_iterators(SrcIterator first, SrcIterator last, DstIterator dst) {
249+
BOOST_FORCEINLINE auto copy_with_2d_iterators(SrcIterator first, SrcIterator last, DstIterator dst) -> DstIterator {
248250
using src_x_iterator = typename SrcIterator::x_iterator;
249251
using dst_x_iterator = typename DstIterator::x_iterator;
250252

@@ -270,9 +272,11 @@ namespace std {
270272
/// \ingroup STLOptimizations
271273
/// \brief std::copy(I1,I1,I2) with I1 and I2 being a iterator_from_2d
272274
template <typename IL, typename OL>
273-
BOOST_FORCEINLINE boost::gil::iterator_from_2d<OL> copy1(boost::gil::iterator_from_2d<IL> first, boost::gil::iterator_from_2d<IL> last, boost::gil::iterator_from_2d<OL> dst) {
275+
BOOST_FORCEINLINE auto copy1(boost::gil::iterator_from_2d<IL> first, boost::gil::iterator_from_2d<IL> last, boost::gil::iterator_from_2d<OL> dst) -> boost::gil::iterator_from_2d<OL>
276+
{
274277
return boost::gil::detail::copy_with_2d_iterators(first,last,dst);
275278
}
279+
276280
} // namespace std
277281

278282
namespace boost { namespace gil {
@@ -307,13 +311,13 @@ class copy_and_convert_pixels_fn : public binary_operation_obj<copy_and_convert_
307311
copy_and_convert_pixels_fn(CC cc_in) : _cc(cc_in) {}
308312
// when the two color spaces are incompatible, a color conversion is performed
309313
template <typename V1, typename V2> BOOST_FORCEINLINE
310-
result_type apply_incompatible(const V1& src, const V2& dst) const {
314+
auto apply_incompatible(const V1& src, const V2& dst) const -> result_type {
311315
copy_pixels(color_converted_view<typename V2::value_type>(src,_cc),dst);
312316
}
313317

314318
// If the two color spaces are compatible, copy_and_convert is just copy
315319
template <typename V1, typename V2> BOOST_FORCEINLINE
316-
result_type apply_compatible(const V1& src, const V2& dst) const {
320+
auto apply_compatible(const V1& src, const V2& dst) const -> result_type {
317321
copy_pixels(src,dst);
318322
}
319323
};

include/boost/gil/bit_aligned_pixel_iterator.hpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,22 @@ struct bit_aligned_pixel_iterator : public iterator_facade<bit_aligned_pixel_ite
6363

6464
/// For some reason operator[] provided by iterator_adaptor returns a custom class that is convertible to reference
6565
/// We require our own reference because it is registered in iterator_traits
66-
reference operator[](difference_type d) const { bit_aligned_pixel_iterator it=*this; it.advance(d); return *it; }
66+
auto operator[](difference_type d) const -> reference { bit_aligned_pixel_iterator it=*this; it.advance(d); return *it; }
6767

68-
reference operator->() const { return **this; }
69-
const bit_range_t& bit_range() const { return _bit_range; }
70-
bit_range_t& bit_range() { return _bit_range; }
68+
auto operator->() const -> reference { return **this; }
69+
auto bit_range() const -> bit_range_t const& { return _bit_range; }
70+
auto bit_range() -> bit_range_t& { return _bit_range; }
7171
private:
7272
bit_range_t _bit_range;
7373
static constexpr int bit_size = NonAlignedPixelReference::bit_size;
7474

7575
friend class boost::iterator_core_access;
76-
reference dereference() const { return NonAlignedPixelReference(_bit_range); }
76+
auto dereference() const -> reference { return NonAlignedPixelReference(_bit_range); }
7777
void increment() { ++_bit_range; }
7878
void decrement() { --_bit_range; }
7979
void advance(difference_type d) { _bit_range.bit_advance(d*bit_size); }
8080

81-
difference_type distance_to(const bit_aligned_pixel_iterator& it) const { return _bit_range.bit_distance_to(it._bit_range) / bit_size; }
81+
auto distance_to(bit_aligned_pixel_iterator const& it) const -> difference_type { return _bit_range.bit_distance_to(it._bit_range) / bit_size; }
8282
bool equal(const bit_aligned_pixel_iterator& it) const { return _bit_range==it._bit_range; }
8383
};
8484

@@ -122,12 +122,14 @@ struct byte_to_memunit<bit_aligned_pixel_iterator<NonAlignedPixelReference>>
122122
{};
123123

124124
template <typename NonAlignedPixelReference>
125-
inline std::ptrdiff_t memunit_step(const bit_aligned_pixel_iterator<NonAlignedPixelReference>&) {
125+
inline auto memunit_step(const bit_aligned_pixel_iterator<NonAlignedPixelReference>&) -> std::ptrdiff_t
126+
{
126127
return NonAlignedPixelReference::bit_size;
127128
}
128129

129130
template <typename NonAlignedPixelReference>
130-
inline std::ptrdiff_t memunit_distance(const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p1, const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p2) {
131+
inline auto memunit_distance(bit_aligned_pixel_iterator<NonAlignedPixelReference> const& p1, bit_aligned_pixel_iterator<NonAlignedPixelReference> const& p2) -> std::ptrdiff_t
132+
{
131133
return (p2.bit_range().current_byte() - p1.bit_range().current_byte())*8 + p2.bit_range().bit_offset() - p1.bit_range().bit_offset();
132134
}
133135

@@ -137,14 +139,15 @@ inline void memunit_advance(bit_aligned_pixel_iterator<NonAlignedPixelReference>
137139
}
138140

139141
template <typename NonAlignedPixelReference>
140-
inline bit_aligned_pixel_iterator<NonAlignedPixelReference> memunit_advanced(const bit_aligned_pixel_iterator<NonAlignedPixelReference>& p, std::ptrdiff_t diff) {
142+
inline auto memunit_advanced(bit_aligned_pixel_iterator<NonAlignedPixelReference> const& p, std::ptrdiff_t diff) -> bit_aligned_pixel_iterator<NonAlignedPixelReference> {
141143
bit_aligned_pixel_iterator<NonAlignedPixelReference> ret=p;
142144
memunit_advance(ret, diff);
143145
return ret;
144146
}
145147

146148
template <typename NonAlignedPixelReference> inline
147-
NonAlignedPixelReference memunit_advanced_ref(bit_aligned_pixel_iterator<NonAlignedPixelReference> it, std::ptrdiff_t diff) {
149+
auto memunit_advanced_ref(bit_aligned_pixel_iterator<NonAlignedPixelReference> it, std::ptrdiff_t diff) -> NonAlignedPixelReference
150+
{
148151
return *memunit_advanced(it,diff);
149152
}
150153
/////////////////////////////
@@ -183,11 +186,14 @@ namespace std {
183186
// It is important to provide an overload of uninitialized_copy for bit_aligned_pixel_iterator. The default STL implementation calls placement new,
184187
// which is not defined for bit_aligned_pixel_iterator.
185188
template <typename NonAlignedPixelReference>
186-
boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> uninitialized_copy(boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> first,
187-
boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> last,
188-
boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> dst) {
189+
auto uninitialized_copy(boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> first,
190+
boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> last,
191+
boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference> dst)
192+
-> boost::gil::bit_aligned_pixel_iterator<NonAlignedPixelReference>
193+
{
189194
return std::copy(first,last,dst);
190195
}
191196

192-
} // namespace std
197+
} // namespace std
198+
193199
#endif

include/boost/gil/bit_aligned_pixel_reference.hpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ class bit_range {
4949
BOOST_ASSERT(bit_offset >= 0 && bit_offset < 8);
5050
}
5151

52-
bit_range(const bit_range& br) : _current_byte(br._current_byte), _bit_offset(br._bit_offset) {}
52+
bit_range(bit_range const& br) : _current_byte(br._current_byte), _bit_offset(br._bit_offset) {}
5353
template <bool M> bit_range(const bit_range<RangeSize,M>& br) : _current_byte(br._current_byte), _bit_offset(br._bit_offset) {}
5454

55-
bit_range& operator=(const bit_range& br) { _current_byte = br._current_byte; _bit_offset=br._bit_offset; return *this; }
56-
bool operator==(const bit_range& br) const { return _current_byte==br._current_byte && _bit_offset==br._bit_offset; }
55+
auto operator=(bit_range const& br) -> bit_range& { _current_byte = br._current_byte; _bit_offset=br._bit_offset; return *this; }
56+
bool operator==(bit_range const& br) const { return _current_byte==br._current_byte && _bit_offset==br._bit_offset; }
5757

58-
bit_range& operator++() {
58+
auto operator++() -> bit_range& {
5959
_current_byte += (_bit_offset+RangeSize) / 8;
6060
_bit_offset = (_bit_offset+RangeSize) % 8;
6161
return *this;
6262
}
63-
bit_range& operator--() { bit_advance(-RangeSize); return *this; }
63+
auto operator--() -> bit_range& { bit_advance(-RangeSize); return *this; }
6464

6565
void bit_advance(difference_type num_bits) {
6666
int new_offset = int(_bit_offset+num_bits);
@@ -71,11 +71,13 @@ class bit_range {
7171
--_current_byte;
7272
}
7373
}
74-
difference_type bit_distance_to(const bit_range& b) const {
74+
75+
auto bit_distance_to(bit_range const& b) const -> difference_type
76+
{
7577
return (b.current_byte() - current_byte())*8 + b.bit_offset()-bit_offset();
7678
}
77-
byte_t* current_byte() const { return _current_byte; }
78-
int bit_offset() const { return _bit_offset; }
79+
auto current_byte() const -> byte_t* { return _current_byte; }
80+
auto bit_offset() const -> int { return _bit_offset; }
7981
};
8082

8183
/// \defgroup ColorBaseModelNonAlignedPixel bit_aligned_pixel_reference
@@ -136,8 +138,10 @@ struct bit_aligned_pixel_reference
136138

137139
bit_aligned_pixel_reference(){}
138140
bit_aligned_pixel_reference(data_ptr_t data_ptr, int bit_offset) : _bit_range(data_ptr, bit_offset) {}
139-
explicit bit_aligned_pixel_reference(const bit_range_t& bit_range) : _bit_range(bit_range) {}
140-
template <bool IsMutable2> bit_aligned_pixel_reference(const bit_aligned_pixel_reference<BitField,ChannelBitSizes,Layout,IsMutable2>& p) : _bit_range(p._bit_range) {}
141+
explicit bit_aligned_pixel_reference(bit_range_t const& bit_range) : _bit_range(bit_range) {}
142+
143+
template <bool IsMutable2>
144+
bit_aligned_pixel_reference(bit_aligned_pixel_reference<BitField,ChannelBitSizes,Layout,IsMutable2> const& p) : _bit_range(p._bit_range) {}
141145

142146
// Grayscale references can be constructed from the channel reference
143147
explicit bit_aligned_pixel_reference(typename kth_element_type<bit_aligned_pixel_reference,0>::type const channel0)
@@ -183,11 +187,12 @@ struct bit_aligned_pixel_reference
183187

184188
auto operator->() const -> bit_aligned_pixel_reference const* { return this; }
185189

186-
bit_range_t const& bit_range() const { return _bit_range; }
190+
auto bit_range() const -> bit_range_t const& { return _bit_range; }
187191

188192
private:
189193
mutable bit_range_t _bit_range;
190-
template <typename B, typename C, typename L, bool M> friend struct bit_aligned_pixel_reference;
194+
template <typename B, typename C, typename L, bool M>
195+
friend struct bit_aligned_pixel_reference;
191196

192197
template <typename Pixel> static void check_compatible() { gil_function_requires<PixelsCompatibleConcept<Pixel,bit_aligned_pixel_reference> >(); }
193198

@@ -369,7 +374,7 @@ namespace std {
369374
// Having three overloads allows us to swap between different (but compatible) models of PixelConcept
370375

371376
template <typename B, typename C, typename L, typename R> inline
372-
void swap(const boost::gil::bit_aligned_pixel_reference<B,C,L,true> x, R& y) {
377+
void swap(boost::gil::bit_aligned_pixel_reference<B,C,L,true> const x, R& y) {
373378
boost::gil::swap_proxy<typename boost::gil::bit_aligned_pixel_reference<B,C,L,true>::value_type>(x,y);
374379
}
375380

@@ -381,7 +386,7 @@ void swap(typename boost::gil::bit_aligned_pixel_reference<B,C,L,true>::value_ty
381386

382387

383388
template <typename B, typename C, typename L> inline
384-
void swap(const boost::gil::bit_aligned_pixel_reference<B,C,L,true> x, const boost::gil::bit_aligned_pixel_reference<B,C,L,true> y) {
389+
void swap(boost::gil::bit_aligned_pixel_reference<B,C,L,true> const x, const boost::gil::bit_aligned_pixel_reference<B,C,L,true> y) {
385390
boost::gil::swap_proxy<typename boost::gil::bit_aligned_pixel_reference<B,C,L,true>::value_type>(x,y);
386391
}
387392

0 commit comments

Comments
 (0)