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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:08:33+00:00 2026-05-22T03:08:33+00:00

Given the below function signatures (and their constraints), would they be considered the same?

  • 0

Given the below function signatures (and their constraints), would they be considered the same? Both pass my unittests, so I am led to believe they may be, but I’d like to know if they are truly identical or if they are different (but behave the same):

Here, the signature constraint refers the parameter names (I realize the runtime information is not available, my assumption is that the compiler uses these to refer to the types of haystack and needle):

T[] find(T, E)(T[] haystack, E needle) 
  if(is(typeof(haystack[0] != needle) == bool)) 
{
  // ...
}

Now, if I update to refer to the types T and E, it still works. I like this form better because it’s explicit that my signature constraint is looking the types (and not runtime information)… and well it’s more concise:

T[] find(T, E)(T[] haystack, E needle) 
  if(is(typeof(T != E) == bool)) 
{
  // ...
}

Are my assumptions correct or am I missing something?

  • 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-22T03:08:34+00:00Added an answer on May 22, 2026 at 3:08 am

    personally I’d use if(is(typeof(T.init != E.init) == bool)) to ensure it’s about the vars of the type

    (and then when you want T to be a range (and losing the array notation it’d be if(isInputRange(T) && is(typeof(T.init.front != E.init) == bool)))


    edit: best way to test things like this is by expanding the test case:

    if we take a different function:

    int binarySearch(T,E)(T[] haystack, E needle)
        if(is(typeof(haystack[0] < needle) == bool)) {
    //...
       return -1;
    }
    

    this compiles and works as you’d expect (barring implementation details…)

    but

    int binarySearch(T,E)(T[] haystack, E needle)
        if(is(typeof(T < E) == bool)) {
    //...
       return -1;
    }
    

    doesn’t (calling binarySearch([1,2,3],0); on it doesn’t compile)

    however like my original answer:

    int binarySearch(T,E)(T[] haystack, E needle)
       if(is(typeof(T.init > E.init) == bool)) {
        //...
        return -1;
    }
    

    this does work like expected

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

Sidebar

Related Questions

Hello friends i am running code given below which contains the setLogTimeEntery function and
Given the one-table design given below how would the following best be queried The
I am trying to implement a function. My code is given below. I want
I am creating a textbutton using actionscript. the code is given below. public function
i am calling the function given below on dropping a tag on an area.
i have function which return list as given below. List<User> lstUsers = SearchUsers(searchText); which
I am currently facing an error in JavaScript. The code is given below function
I have 3 files (file1.php, file2.php and file3.php). Their contents are given below. When
In the below given function i am trying to create an alertDialog box with
I have given below simplified JavaScript problem. var PROJ=(function(){ var tags={}, var lock=true; function

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.