How to assign all elements but one in ada?
If i have this
element_to_ignore : integer := 3;
a : array(1..4) := (5,3,2,6);
b : array(1..a'length-1) := a( all but element_to_ignore );
I need this result:
b = (5,3,6)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Use slices and array concatenation.
This program demonstrates how to do it, and also fixes some problems in your code (you didn’t specify the element types of the arrays, for example):
You can also omit the bounds on the declarations of
AandBand let them get the bounds from the initialization. It does mean that whenElement_To_Ignoreis 1,Bwill have bounds2..4rather than1..3. That shouldn’t be a problem as long as you consistently refer toB'First,B'Last, andB'Rangerather than using hardwired constants. It also mean that settingElement_To_Ignoreto 0 or 5 results inBbeing set to(5,3,2,6).I’ve created a more elaborate demo here.