Find a char among string (string.findAmong.char)

BoQsc vaidas.boqsc at gmail.com
Mon Jul 5 18:45:10 UTC 2021


I get an error when I try to find that letter is among alphabet.
> onlineapp.d(13): Error: template 
> `std.algorithm.searching.findAmong` cannot deduce function from 
> argument types `!()(immutable(char), immutable(string))`, 
> candidates are:
> /dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/searching.d(2694):        `findAmong(alias pred = "a == b", InputRange, ForwardRange)(InputRange seq, ForwardRange choices)`
>   with `pred = "a == b",
>        InputRange = immutable(char),
>        ForwardRange = string`
>   must satisfy the following constraint:
> `       isInputRange!InputRange`


This is the code: You can run it at: 
https://run.dlang.io/is/5cvuUZ
  import std;
  void main()
  {
      alias alphabet = letters;
      char[26] letters = ['a','b', 'c', 'd', 'e',
                          'f', 'g', 'h', 'i', 'j',
                          'k', 'l', 'm', 'n', 'o',
                          'p', 'q', 'r', 's', 't',
                          'u', 'v', 'w', 'x', 'y', 'z'];

      string wordExample = "Book.";
      foreach (letter; wordExample){
          if (letter.findAmong(alphabet)){
              write("found");
          }
      	write(letter);
      }
  						
  }





More information about the Digitalmars-d-learn mailing list