Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #164714

Re: on how to use the third argument of strncmp()

From Bonita Montero <Bonita.Montero@gmail.com>
Newsgroups comp.lang.c
Subject Re: on how to use the third argument of strncmp()
Date 2022-01-29 16:06 +0100
Organization A noiseless patient Spider
Message-ID <st3l4t$u7d$1@dont-email.me> (permalink)
References <86czkbd4ey.fsf@levado.to> <chine.bleu-2381BF.13431128012022@reader.eternal-september.org> <st3cpn$fe$1@dont-email.me>

Show all headers | View raw


Am 29.01.2022 um 13:43 schrieb Bonita Montero:

> Doesn't this look better ?
> 
> #include <cstddef>
> #include <concepts>
> #include <string_view>
> 
> template<typename char_t = char>
> 	requires std::is_same_v<char_t, char> || std::is_same_v<char_t, wchar_t>
> inline
> bool begins_with( std::basic_string_view<char_t> const &str, std::basic_string_view<char_t> const &cmp )
> {
> 	return str.starts_with( cmp );
> }
> 
> #include <iostream>
> 
> using namespace std;
> 
> int main()
> {
> 	cout << begins_with( "hello world"sv, "hello"sv ) << endl;
> }
And for the above code everything inside the begins_with-call is
compile-time evaluated. And even if wouldn't be: the starts_with
call could check if cmp's length is shorter than str and and skip
the comparison, thereby being faster than the strncmp-solution in
plain C.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

on how to use the third argument of strncmp() Meredith Montgomery <mmontgomery@levado.to> - 2022-01-28 16:52 -0300
  Re: on how to use the third argument of strncmp() Mateusz Viste <mateusz@xyz.invalid> - 2022-01-28 21:07 +0100
    Re: on how to use the third argument of strncmp() Meredith Montgomery <mmontgomery@levado.to> - 2022-01-28 18:17 -0300
      Re: on how to use the third argument of strncmp() Mateusz Viste <mateusz@xyz.invalid> - 2022-01-28 22:35 +0100
      Re: on how to use the third argument of strncmp() Vir Campestris <vir.campestris@invalid.invalid> - 2022-02-02 22:01 +0000
    Re: on how to use the third argument of strncmp() Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-01-28 18:37 -0800
      Re: on how to use the third argument of strncmp() scott@slp53.sl.home (Scott Lurndal) - 2022-01-29 15:32 +0000
      Re: on how to use the third argument of strncmp() Bonita Montero <Bonita.Montero@gmail.com> - 2022-01-29 19:02 +0100
  Re: on how to use the third argument of strncmp() scott@slp53.sl.home (Scott Lurndal) - 2022-01-28 21:26 +0000
    Re: on how to use the third argument of strncmp() Mike Terry <news.dead.person.stones@darjeeling.plus.com> - 2022-01-28 22:03 +0000
      Re: on how to use the third argument of strncmp() scott@slp53.sl.home (Scott Lurndal) - 2022-01-29 15:31 +0000
  Re: on how to use the third argument of strncmp() Siri Cruise <chine.bleu@yahoo.com> - 2022-01-28 13:43 -0800
    Re: on how to use the third argument of strncmp() Bonita Montero <Bonita.Montero@gmail.com> - 2022-01-29 13:43 +0100
      Re: on how to use the third argument of strncmp() Bonita Montero <Bonita.Montero@gmail.com> - 2022-01-29 16:06 +0100
        Re: on how to use the third argument of strncmp() Bonita Montero <Bonita.Montero@gmail.com> - 2022-01-29 16:09 +0100
  Re: on how to use the third argument of strncmp() Kaz Kylheku <480-992-1380@kylheku.com> - 2022-01-28 21:54 +0000
    Re: on how to use the third argument of strncmp() Meredith Montgomery <mmontgomery@levado.to> - 2022-01-28 21:47 -0300
  Re: on how to use the third argument of strncmp() James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-01-28 19:40 -0500
    Re: on how to use the third argument of strncmp() Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-01-29 03:53 -0800
      Re: on how to use the third argument of strncmp() Bonita Montero <Bonita.Montero@gmail.com> - 2022-01-29 19:01 +0100
    Re: on how to use the third argument of strncmp() Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2022-01-29 10:54 -0700
      Re: on how to use the third argument of strncmp() James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-01-29 14:55 -0500
  Re: on how to use the third argument of strncmp() Manfred <noname@add.invalid> - 2022-01-30 04:03 +0100
    Re: on how to use the third argument of strncmp() Meredith Montgomery <mmontgomery@levado.to> - 2022-01-30 10:02 -0300
      Re: on how to use the third argument of strncmp() Dolores Filandro <dolfiland8@gmail.com> - 2022-02-03 18:48 -0800

csiph-web