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 7979195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:42:48+00:00 2026-06-04T09:42:48+00:00

How std.range.ElementType should be used in template constraints? I assumed this way, but I

  • 0

How std.range.ElementType should be used in template constraints?

I assumed this way, but I was wrong

import std.range;
auto f(T)(T x)
    if (ElementType!(T) is uint) // adding this line causes lot of error messages 
                                // first of which is:  found ')' when expecting '.' following uint
{
    return x;
}
f(map!"a"([1,2,3,4]));
  • 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-06-04T09:42:49+00:00Added an answer on June 4, 2026 at 9:42 am

    The is expression is not the same as the is operator. Documentation on the is expression is here: http://dlang.org/expression.html#IsExpression. The is operator does a bitwise comparison of values whereas the is expression compares types (and does crazy pattern matching). Your constraint should be written like this:

    auto f(T)(T x)
         if (is(ElementType!(T) == uint))
    

    Or, if you want to match anything implicitly convertible to a uint as well:

    auto f(T)(T x)
         if (is(ElementType!(T) : uint))
    

    Further, I’ve fixed your invocations of ElementType, adding the “!” where appropriate; ElementType is a template, not a function.

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

Sidebar

Related Questions

std::string x(x); This crashes very badly on my compiler. Does this mean I should
Sitation: overview: I have something like this: std::vector<SomeType> values; std::vector<int> indexes; struct Range{ int
I'm looking for a way that prevents std::vectors/std::strings from growing in a given range
std::swap() is used by many std containers (such as std::list and std::vector ) during
std::vector<std::pair<std::string > > can be used to store a list of a pair of
I need to check if a std::set contains element/elements in a range. For example,
I'd like to test a std::string for containing numbers of any range e.g 5
Let's say you have a c++0x std::array member of a template class and you
Benefits of C++11 std::array s when programming have been explained by experts, but there
If I try to use std.algorithm.fill(Range1, Range2)(Range1 range, Range2 filler), I keep getting the

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.