[vlc-devel] [PATCH] mkv: remove deprecated std function

Alexandre Janniaux ajanni at videolabs.io
Wed Dec 11 15:07:37 CET 2019


Actually, I was told that bind wasn't really friendly and
should be replaced by lambda functions. But with lambda
function it is written like this:

```
diff --git a/modules/demux/mkv/chapters.cpp b/modules/demux/mkv/chapters.cpp
index 3d69da52df..68a212e259 100644
--- a/modules/demux/mkv/chapters.cpp
+++ b/modules/demux/mkv/chapters.cpp
@@ -147,14 +147,13 @@ bool chapter_item_c::EnterLeaveHelper_ ( bool do_subs,
     bool f_result = false;     f_result |= std::count_if ( codecs.begin (), codecs.end (),
-      std::mem_fn (co_cb)
+      [co_cb](auto codec){ return (codec->*co_cb)(); }
     );     if ( do_subs )
     {
-        using std::placeholders::_1;
         f_result |= count_if ( sub_chapters.begin (), sub_chapters.end (),
-          std::bind( std::mem_fn( ch_cb ), _1, true )
+          [ch_cb](auto sub_chapter){ return (sub_chapter->*ch_cb)(true); }
         );
     }
```

What do you prefer?

Regards,
--
Alexandre Janniaux
Videolabs


On Wed, Dec 11, 2019 at 11:57:13AM +0100, Alexandre Janniaux wrote:
> std::mem_fun and std::bind2nd have been deprecated in C++11 and will be
> removed in C++17. They were replaced by std::mem_fn and std::bind which
> are easier to use.
> ---
>  modules/demux/mkv/chapters.cpp | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/modules/demux/mkv/chapters.cpp b/modules/demux/mkv/chapters.cpp
> index 8d9f5da899..3d69da52df 100644
> --- a/modules/demux/mkv/chapters.cpp
> +++ b/modules/demux/mkv/chapters.cpp
> @@ -147,13 +147,14 @@ bool chapter_item_c::EnterLeaveHelper_ ( bool do_subs,
>      bool f_result = false;
>
>      f_result |= std::count_if ( codecs.begin (), codecs.end (),
> -      std::mem_fun (co_cb)
> +      std::mem_fn (co_cb)
>      );
>
>      if ( do_subs )
>      {
> +        using std::placeholders::_1;
>          f_result |= count_if ( sub_chapters.begin (), sub_chapters.end (),
> -          std::bind2nd( std::mem_fun( ch_cb ), true )
> +          std::bind( std::mem_fn( ch_cb ), _1, true )
>          );
>      }
>
> --
> 2.24.1
>


More information about the vlc-devel mailing list