Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6049751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:36:43+00:00 2026-05-23T07:36:43+00:00

If I try to use std.algorithm.fill(Range1, Range2)(Range1 range, Range2 filler), I keep getting the

  • 0

If I try to use std.algorithm.fill(Range1, Range2)(Range1 range, Range2 filler), I keep getting the error message that no template match could be found. It looks like the compiler is trying to match with fill (Range, Value) rather than the other one.

auto test = new char[256];
fill(test, "abc".dup);

Is it not possible to fill a character array using fill?

The error

test.d(13): Error: template
std.algorithm.fill(Range,Value) if
(isForwardRange!(Range) &&
is(typeof(range.front = filler))) does
not match any function template
declaration

test.d(13): Error:
template
std.algorithm.fill(Range,Value) if
(isForwardRange!(Range) &&
is(typeof(range.front = filler)))
cannot deduce t emplate function from
argument types !()(char[],char[])

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:36:44+00:00Added an answer on May 23, 2026 at 7:36 am

    std.algorithm.fill takes a range. All string types are ranges of dchar. This is because they’re all unicode. char is a UTF-8 code unit wchar is a UTF-16 code unit, and dchar is a UTF-32 code unit. Multiple code units make up a code point, which is a character. For UTF-8, a code point could be up to 6 code units. For UTF-16, it could be up to 2. For UTF-32, 1 code unit is always 1 code point, so a dchar is always guaranteed to be a valid character. char and wchar by themselves, however, are not guaranteed to be valid characters at all, and it’s generally a bug if you see an individual char or wchar used. Multiple chars or wchars often must be combined to make up a single character. So, you can’t deal with chars or wchars individually. That’s why if you’re iterating over a string of any kind with foreach, you should always give its type as dchar.

    foreach(dchar c; str)
        ...
    

    If you didn’t specify dchar, then it would be whatever the character type of str is, which would invariably cause bugs unless str were an array of dchar, because you’d end up with code units (pieces of characters) instead of code points (whole characters). Only dchars can be dealt with individually.

    It’s because of all of this that all string types and character arrays are considered to be ranges of dchar, regardless of what their actual element types are. So, when you call popFront on a string, it could pop off a lot more than just one char or wchar. And if you call front, it may have to decode multiple chars or wchars to return the dchar that is the first character in the string. This means that you can’t treat char or wchar arrays as being random access. The 4th character could be the 4th element, or it could be the 12th. And regardless of which index it starts at, it could be multiple code units long, so you can’t just grab a random index in char or wchar array and expect it to be valid. So, arrays of char and wchar are not random access ranges. They’re not output ranges either.

    Think about it. Let’s take the character '\U00010143' () for instance. It has a code unit length of 4 for UTF-8 and 2 for UTF-16. You can’t just fill any random char or wchar array with it. If it’s a char array, and its length isn’t a multiple of 4, then the last () isn’t going to fit. If it’s a wchar array, and its length isn’t a multiple of 2, then it’ll have the same problem. So, it really doesn’t work to use a function like fill on a char or wchar array.

    Now, it’ll work just fine with a dchar array. Because a UTF-32 code unit is guaranteed to be a code point, every character in a dchar array is one element, and it can be both a random access range and an output range. So, if you want to use a function like fill with character arrays, you need to use an array of dchar. You can use std.conv.to to convert it to the type of character array that you want after that, but you can’t fill an array of char or wchar directly.

    Arrays of char and wchar work great with algorithms which don’t need output ranges or random access ranges, but they don’t work with those. For those, you need arrays of dchar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting an error message that says undefined reference to encrypt(int, std::list<int, std::allocator<int>
I'm getting the following error when I try to use the JSTL XML taglib:
When I try to use the code below I get a duplicate variable error
I get the above error whenever I try and use ActionLink ? I've only
I'm getting an error here that says I haven't defined a method, but it
I'm trying to use the C++ standard library's find algorithm like this: template<class T>
When I try to use an ssh command in a shell script, the command
When I try to use curl or file_get_contents to read something like http://example.com/python/json/ from
I am try to use stringWithFormat to set a numerical value on the text
When I try to use introspection to look at what methods are available on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.